Jump to content


Photo

guestbook problem


  • Please log in to reply
6 replies to this topic

#1 2wasted

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

Posted 30 May 2006 - 06:16 PM

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

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 30 May 2006 - 06:28 PM

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

mysql_connect(HOST, USER, PASSWORD) or die(mysql_error());
mysql_select_db(DATABASE) or die(mysql_error());;

Put that code on the top of your script; remember to set the right variables.
~ D Kuang

#3 2wasted

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

Posted 30 May 2006 - 06:54 PM

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

mysql_connect(HOST, USER, PASSWORD) or die(mysql_error());
mysql_select_db(DATABASE) or die(mysql_error());;

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


#4 kenrbnsn

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

Posted 30 May 2006 - 06:58 PM

Each time the script is started, the DB connections have to be started, they do not persist across pages.

Ken

#5 2wasted

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

Posted 30 May 2006 - 07:57 PM

[!--quoteo(post=378472:date=May 30 2006, 01:58 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 30 2006, 01:58 PM) View Post[/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>



#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 May 2006 - 08:10 PM

£result - shouldn't those be $result?
Legend has it that reading the manual never killed anyone.
My site

#7 2wasted

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

Posted 31 May 2006 - 12:58 AM

[!--quoteo(post=378499:date=May 30 2006, 03:10 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 30 2006, 03:10 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
£result - shouldn't those be $result?
[/quote]
lol,yup thats fixed afew of the problems:-)
Thanks
Charlie




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users