Jump to content

Archived

This topic is now archived and is closed to further replies.

2wasted

guestbook problem

Recommended Posts

i doing a guestbook to try and learn php&mysql....it posts to the database but not back on the page:-(the error is "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\phpvid\guestbook2.php on line 47" .i'll mark line 47 with "<<<<"

<?php require_once('Connections/localhost.php'); ?>
<?php
mysql_select_db($database_localhost, $localhost);
$query_connection = "SELECT * FROM guestbook";
$connection = mysql_query($query_connection, $localhost) or die(mysql_error());
$row_connection = mysql_fetch_assoc($connection);
$totalRows_connection = mysql_num_rows($connection);
$name = $_POST["txt_name"];
//write to db if there is data in name text box
$len = strlen($name);
if ($len > 0)
{
$email = $_POST["txt_email"];
$comment = $_POST["txt_comment"];
$date = time();


$query = "INSERT INTO guestbook (autoID, name, email, comment, date_auto) VALUES (NULL, '$name', '$email', '$comment', '$date')";

mysql_query($query) or die(mysql_error());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Guestbook</title>
</head>
<body>
<center>
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="post">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1">
Name: <input type="text" name="txt_name" >&nbsp;
Email: <input type="text" name="txt_email" ><br><br>
Comment:<br>
<textarea style="width: 75%" rows="10" name="txt_comment"></textarea>
<center><input type="submit" value="Submit"></center>
</font>
</form>
<table background="#AAAAAA" border="0" width="75%" cellspacing="1" cellpadding="2">

<?PHP
$query = "SELECT * FROM questbook ORDER BY date_auto";
$result = mysql_query($query);
for ($i = 0; $i < mysql_num_rows($result); $i++) [!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]<<<<here is the line:-)[!--colorc--][/span][!--/colorc--]
{
$name = mysql_result($result, $i, "name");
$email = mysql_result($result, $i, "email");
$email_len = strlen ($email);
$comment = mysql_result($result, $i, "comment");
$date = mysql_result($result, $i, "date_auto");
$show_date = date("H:i:s d/m/Y", $date);
echo '
<tb>
<tb width="100%" bgcolor="#EEEEEE">
<font face="arial" size="2">';
if ($email_len > 0)
{
echo '<b>Name:</b><a href="mailto:'.$email.'>"'.$name.'</a>';
}
else
{
echo '<b>Name:</b> '.$name;
}
echo '
<br>
<b>Comment:</b> '.$comment.'
</font>
<td>
<tb width="1%" valign="top" nowrap bgcolor="#EEEEEE">
<font face="arial" size="2">
<b>Date: </b> '.$show_date.'
</font>
</tb>
</tr>
';
}
?>
</table>
</body>
</html>
Thx For any help
Charlie

Share this post


Link to post
Share on other sites
Check for query errors

$query = "SELECT * FROM questbook ORDER BY date_auto";
$result = mysql_query($query) [!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]or die(mysql_error())[!--colorc--][/span][!--/colorc--];

Share this post


Link to post
Share on other sites
it says "Table 'databasename.questbook' doesn't exist" but it just posted the info from the form into it..
Thx
Charlie

Share this post


Link to post
Share on other sites
Look closely at your table names...

The correct on is "[b]guestbook[/b]", the incorrect one is spelled "[b][!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]q[!--colorc--][/span][!--/colorc--]uestbook[/b]".

Ken

Share this post


Link to post
Share on other sites
[!--quoteo(post=379877:date=Jun 4 2006, 09:04 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 4 2006, 09:04 AM) [snapback]379877[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Look closely at your table names...

The correct on is "[b]guestbook[/b]", the incorrect one is spelled "[b][!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]q[!--colorc--][/span][!--/colorc--]uestbook[/b]".

Ken
[/quote]
lol,thx
Charlie

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.