Jump to content

guestbook problem


2wasted

Recommended Posts

lo all,
i'am doing a guestbook thing:-)it posts 2 the mysql database np but when i try and post it back in the web page i get..
Warning: mysql_query(): supplied resource is not a valid MySQL-Link resource in C:\wamp\www\phpvid\guestbook.php on line 51

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\phpvid\guestbook.php on line 52

this is the code
<?PHP <that is line 49
$query = "SELECT * FROM guestbook ORDER BY date_auto";
$result = mysql_query($query, $connection);
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$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 m/d/Y", $date);
echo '
<tr>
<td width="50%" 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>
<tb>
<tb width ="1%" valign="top" nowrap bgcolor="#EEEEEE">
<font>
<b>Date: </b> '.$show_date.'
</font>
</tb>
</tr>
'
?>
thx for any help
Charlie
Link to comment
https://forums.phpfreaks.com/topic/10787-guestbook-problem/
Share on other sites

Chances are, you didn't connect to a database or maybe didn't select a database:

[code]mysql_connect(HOST, USER, PASSWORD) or die(mysql_error());
mysql_select_db(DATABASE) or die(mysql_error());;[/code]

Put that code on the top of your script; remember to set the right variables.
Link to comment
https://forums.phpfreaks.com/topic/10787-guestbook-problem/#findComment-40327
Share on other sites

[!--quoteo(post=378463:date=May 30 2006, 01:28 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 30 2006, 01:28 PM) [snapback]378463[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Chances are, you didn't connect to a database or maybe didn't select a database:

[code]mysql_connect(HOST, USER, PASSWORD) or die(mysql_error());
mysql_select_db(DATABASE) or die(mysql_error());;[/code]

Put that code on the top of your script; remember to set the right variables.
[/quote]
the connection is working,cause anything u post in the guestbook goes into the mysql DB
Thx
Charlie
Link to comment
https://forums.phpfreaks.com/topic/10787-guestbook-problem/#findComment-40332
Share on other sites

[!--quoteo(post=378472:date=May 30 2006, 01:58 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 30 2006, 01:58 PM) [snapback]378472[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Each time the script is started, the DB connections have to be started, they do not persist across pages.

Ken
[/quote]
everything is on the 1 page,and i dont have anything telling it to stop the conection.
Thx
Charlie
P.s here is the full page
<?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">
<p>Name:
<input name="txt_name" type="text" />
Email: <input name="txt_email" type="text" value="<?php echo strtolower($row_connection['email']); ?>" />
<br>
<br>
Comment:<br />
</p>
<textarea style="width: 75%" row="10" name="txt_comment"></textarea>
<center><input type="submit" value="Submit" /></center>
</form>

<table width="50%" cellspacing="1">
<tr>
<td>&nbsp;</td>
</tr>
<?PHP
$query = "SELECT * FROM guestbook ORDER BY date_auto";
$result = mysql_query($query, $connection);
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$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 m/d/Y", $date);
echo '
<tr>
<td width="50%" 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>
<tb>
<tb width ="1%" valign="top" nowrap bgcolor="#EEEEEE">
<font>
<b>Date: </b> '.$show_date.'
</font>
</tb>
</tr>
'
?>
</table>
<p>&nbsp;</p>
</center>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/10787-guestbook-problem/#findComment-40357
Share on other sites

[!--quoteo(post=378499:date=May 30 2006, 03:10 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 30 2006, 03:10 PM) [snapback]378499[/snapback][/div][div class=\'quotemain\'][!--quotec--]
£result - shouldn't those be $result?
[/quote]
lol,yup thats fixed afew of the problems:-)
Thanks
Charlie
Link to comment
https://forums.phpfreaks.com/topic/10787-guestbook-problem/#findComment-40413
Share on other sites

Archived

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

×
×
  • Create New...

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.