2wasted Posted June 3, 2006 Share Posted June 3, 2006 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'); ?><?phpmysql_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" > 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 helpCharlie Quote Link to comment https://forums.phpfreaks.com/topic/11127-guestbook-problem/ Share on other sites More sharing options...
Barand Posted June 4, 2006 Share Posted June 4, 2006 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--]; Quote Link to comment https://forums.phpfreaks.com/topic/11127-guestbook-problem/#findComment-41635 Share on other sites More sharing options...
2wasted Posted June 4, 2006 Author Share Posted June 4, 2006 it says "Table 'databasename.questbook' doesn't exist" but it just posted the info from the form into it..ThxCharlie Quote Link to comment https://forums.phpfreaks.com/topic/11127-guestbook-problem/#findComment-41693 Share on other sites More sharing options...
kenrbnsn Posted June 4, 2006 Share Posted June 4, 2006 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 Link to comment https://forums.phpfreaks.com/topic/11127-guestbook-problem/#findComment-41705 Share on other sites More sharing options...
2wasted Posted June 4, 2006 Author Share Posted June 4, 2006 [!--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,thxCharlie Quote Link to comment https://forums.phpfreaks.com/topic/11127-guestbook-problem/#findComment-41712 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.