Please help me link my mysql database to my website using php. I keep getting...

  • Thread starter Thread starter Yiaggi
  • Start date Start date
Y

Yiaggi

Guest
...a wierd error msg!? Hi guys,

I have tried to post this question a couple of times but have made a few spelling mistakes in my coding & have only got answers regarding that! If you have the time to read through this then I will give you as many of those 'star' thingies as you want for the correct answer! This problem has become an ultimate pain in the ass and is taking days to solve so you can consider it your good deed for the day!

[NB I have changed my actual username & password for 'myusername' & 'mypassword' so that I can protect my details. I know it wont work without me entering them!]

Right .... here goes!

I have a website that I need to add a simple guestbook too. I am a web designer but this is my first go at programming etc.

*I have opened a database connection through my web servers website & acquired my username & set my password.

*I have my mySQL database set up and called 'sm22628'

*Within that I have a table called 'guestbook' to hold the information entered on my page.

*In that table is "id (primary key), name, email, comment, datetime.

*On my website I have 3 php pages called:

guestbook.php
addguestbook.php
viewguestbook.php [all coding displayed below]

I have uploaded all of this to my server and when I try to post my first guestbook message I get a random message that say's:

"Table 'sm22628.guestbook' doesn't exist"

----------------------------------------------------------------------------------------------------

This is very strange for 2 reason:

1/ It obviously does exist - I wrote it and can access it through the mySQL command prompt.

2/ The table that is suggested 'doesn't exist' is named as 'sm22628.guestbook' which is obviously a mixture of the database name and the table name. As you can see below in my coding - it doesnt appear like that once!

---------------------------------------------------------------------------------------------------

I feel I am close to getting this working - is just this last niggly bit and I will be away! Can anyone tell me why this is happening?! Any help would be truly appreciated! Please find below - the php coding for my 3 pages.

Kind Regards :)

----------------------------------------------------------------------------------------------------

ADDGUESTBOOK.PHP
-----------------------------------
<?php
$host="localhost"; // Host name
$username="myusername"; // Mysql username
$password="mypassword"; // Mysql password
$db_name="sm22628"; // Database name
$tbl_name="guestbook"; // Table name

$db_connection = mysql_connect($host, $username, $password)or die("cannot connect server ");
mysql_select_db($db_name, $db_connection)or die("cannot select DB ". mysql_error());

$datetime=date("y-m-d h:i:s"); //date time

$sql="INSERT INTO guestbook(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysql_query($sql) or die (mysql_error());

//check if query successful
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page
}

else {
echo "ERROR - query not successfull";
}

mysql_close();
?>

VIEWGUESTBOOK.PHP
-------------------------------------
<?php

$host="localhost"; // Host name
$username="myusername"; // Mysql username
$password="mypassword"; // Mysql password
$db_name="sm22628"; // Database name
$tbl_name="guestbook"; // Table name

$db_connection = mysql_connect($host, $username, $password)or die("cannot connect server ");
mysql_select_db($db_name, $db_connection)or die("cannot select DB ". mysql_error());

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){
?>

GUESTBOOK.PHP
----------------------------
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form id="form1" name="form1" method="post" action="addguestbook.php">
<td>
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="117">Name</td>
<td width="14">:</td>
<td width="357"><input name="name" type="text" id="name" size="40" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email" size="40" /></td>
</tr>
<tr>
<td valign="top">Comment</td>
<td valign="top">:</td>
<td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td>
</tr>
<tr>
<td>*</td>
<td>*</td>
<td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong><a href="viewguestbook.php">View Guestbook</a> </strong></td>
</tr>
</table>
</td>
</tr>
</table>

PLEASE HELP IF YOU CAN! I may jump off a big bridge otherwise ;-)
 
Hi
If you log onto Macromedia home page and search for tutorials on ASP, there are absolutely loads of them.

I have been down a similar road but chose to use PHP, there are far more ASP tutorials than PHP ones available.
 
Back
Top