Hi guys,
I have designed a very simple guestbook using a mysql database and php to link to my website but am having problems getting it going. Am fairly new to this kind of programming so I am sure its something simple ….. Basically …..
I have a mysql database called MRCADB
& a table within called GUESTBOOK
I have 3 php pages:
GUESTBOOK.PHP
—————————-
[THAT SEEMS TO WORK FINE & OFFER A PAGE TO ENTER THE MESSAGE ETC]
ADD GUESTBOOK.PHP
————————————
<?php
$host="localhost"; // Host name
$username="myusername"; // Mysql username
$password="mypassword"; // Mysql password
$db_name="mrcadb"; // Database name
$tbl_name="guestbook"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$datetime=date("y-m-d h:i:s"); //date time
$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysql_query($sql);
//check if query successful
if($result){
echo "Successful";
echo "
“;
echo “View guestbook“; // link to view guestbook page
}
else {
echo “ERROR”;
}
mysql_close();
?>
and then finally:
VIEWGUESTBOOK.PHP
————————————-
| ID |
: |
|
| Name |
: |
|
| Email |
: |
|
| Comment |
: |
|
| Date/Time |
: |
|
|
————————————–…
Im sure that seems fairly straight forward to you php geniuses!
I have linked the GUESTBOOK.PHP page to my index and when you click onto the link it comes up with the form to add to the guestbook – as I expected.
When I try adding to the guestbook I get an error message that reads “CANNOT SELECT DB”
Further – if I try to view ADDGUESTBOOK.PHP or VIEWGUESTBOOK.PHP I get the same message.
It is obvious that it cannot select the database …. i’m just not sure why! Am I right in thinking that it is connecting to mysql but not finding the database within?
I have set up the mysql on my web server etc – it must just be something small! Aggggghhhhhhhh! Any idea’s?!
Ta in advance! :S
PS … I know that I have used some capitals etc in this message. In my script everything is lowercase so please dont offer that as an answer!