Jump to content


Photo

guestbook problem


  • Please log in to reply
4 replies to this topic

#1 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 03 June 2006 - 11:45 PM

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...nsitional.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


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 04 June 2006 - 04:41 AM

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--];

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 04 June 2006 - 01:27 PM

it says "Table 'databasename.questbook' doesn't exist" but it just posted the info from the form into it..
Thx
Charlie

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 June 2006 - 02:04 PM

Look closely at your table names...

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

Ken

#5 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 04 June 2006 - 02:19 PM

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

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

Ken
[/quote]
lol,thx
Charlie





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users