I'm trying to run this code but there is error message:
PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
<?php
if (mysql_connect('localhost','root','') && mysql_select_db('guestbook'))
{
//echo 'connected today';
$time= time();
$errors= array();
if (isset($_POST['guestbook_name'], $_POST['guestbook_email'], $_POST['guestbook_message']))
{
$guestbook_name = mysql_real_escape_string(htmlentities($_POST['guestbook_name']));
$guestbook_email = mysql_real_escape_string(htmlentities($_POST['guestbook_email']));
$guestbook_message = mysql_real_escape_string(htmlentities($_POST['guestbook_message']));
if (empty($guestbook_name) || empty($guestbook_email) || empty($guestbook_message))
{
$errors[] = 'All the feilds are required';
}
if (strlen($guestbook_name)>25 || strlen($guestbook_email)>255 || strlen('$guestbook_message')>255)
{
$errors[] = 'One or more feilds exceeded the character limit';
}
if (empty($errors))
{
$insert ="INSERT INTO 'entries' VALUES ('','$time','$guestbook_name','$guestbook_email','$guestbook_message')";
if (mysql_query($insert))
{
//echo 'sucess';
header('Location: '.$_SERVER['PHP_SELF']);
}
else
{
$errors[]= 'Something went wrong, try again';
}
}
else
{
foreach($errors as $errors)
{
echo '<p><strong>'.$errors. '</strong></P>';
}
}
}
//display data
$entries = mysql_query("SELECT 'timestamp','name','email','message' FROM 'entries' ORDER BY 'timestamp' DESC");
if (mysql_num_rows($entries)==0)
{
echo 'No entries,yet';
}
else
{
while($entries_row= mysql_fetch_assoc($entries))
{
$entries_timestamp =date('D M Y @ h:i:s',$entries_row['timestamp']);
$entries_name =$entries_row['name'];
$entries_email =$entries_row['email'];
$entries_message =$entries_row['message'];
echo '<p><strong>Posted by '.$entries_name.' ('.$entries_email.') on '.$entries_timestamp.'</strong>:<br> '.$entries_message.'</P>';
}
// echo'Entries found';
}
}
else
{
echo 'could not connect! oh no problem again';
}
?>
<hr>
<hr>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="POST">
<strong>Post something...</strong><br>
Name:<br><input type="text" name="guestbook_name" maxlength="25"><br>
Email:<br><input type="text" name="guestbook_email" maxlength="255"><br>
Message:<br><textarea name="guestbook_message" rows="5" cols="40 "maxlength="255"></textarea><br>
<input type="submit" value="post">
</form>
<hr>
<hr>