<?php session_start(); if($_SESSION['s_logged_n'] == 'true'){ include 'process.php'; date_default_timezone_set('Asia/Hong_Kong'); if(isset($_POST['action'])){ $gname = $_SESSION['s_name']; $gemail = $_SESSION['s_email']; $gmsg = $_POST['gmsg']; $date = date('F j, Y, g:i a'); $sql = "insert into guestbook "; $sql .= "(guestname, guestemail, guestmessage, guestdate)"; $sql .=" values('$gname','$gemail','$gmsg','$date')"; mysql_query($sql); } ?> <form name = "form1" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" onSubmit="return validateForm(form1)"> <table> <tr> <td class="c_text">Name: <?php echo $_SESSION['s_name']; ?> </td> </tr> <tr> <td class="c_text"> Email: <?php echo $_SESSION['s_email']; ?> </td> </tr> </table> <font class="c_text">Message:</font> <textarea class="form2 m_text" cols="35" rows="6" name="gmsg"></textarea> <br> <input type="submit" class="form3 m_text" value="Send" name="action"> <input name="reset" class="form3 m_text" type="reset" value="Clear"> <br><br> </form> <?php $display=10; if(isset($_GET['np'])) { $num_pages= $_GET['np']; } else{ $query="SELECT COUNT (*) FROM guestbook ORDER BY guestid DESC"; $result=mysql_query($query); $row=mysql_fetch_array($result); $num_records=$row[0]; if ($num_records>$display) { $num_pages = ceil($num_records/$display); } else{ $num_pages=1; } } if(isset($_GET['s'])) { $start=$_GET['s']; } else{ $start=0; } $results = mysql_query("select * from guestbook order by guestid desc limit $start, $display"); while($data = mysql_fetch_object($results)){ echo "<table width=\"418\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" >"; echo " <tr>\n"; echo "<td class=\"c_text\" align=\"left\" width=\"60%\">Name: "; echo "<a href=\"mailto:".$data->guestemail."\" class=\"c1_text\">".$data->guestname."</a>"; echo "</td>\n"; echo "<td class=\"c_text\" align=\"right\" width=\"40%\">".$data->guestdate."</td>\n"; echo " </tr>\n"; echo "<tr>\n"; echo " <td class=\"c_text\" colspan=\"2\" align=\"left\">Message: ".$data->guestmessage."</td>\n"; echo " </tr>\n"; echo "</table><br>"; } if ($num_pages>1) { echo '<br><p>'; $current_page=($start/$display)+1; if($current_page!=1) { echo '<a href="guestbook.php?s='.($start-$display). '&np='.$num_pages.'">Previous</a>'; } for($i=1; i<=$num_pages; $i++) { if($i!=$current_page) { echo '<a href="guestbook.php?s='. (($display * ($i-1))).'&np='.$num_pages.' ">' .$i. '</a>'; } else{ echo $i .' '; } } if($current_page != $num_pages) { echo '<a href="guestbook.php?s='. ($start+$display). '&np=' .$num_pages.' ">Next</a>'; } echo '<p>'; } ?> <br> <?php } else { /*echo $_SESSION['s_logged_n'].'b'; echo $_SESSION['s_username'].'c'; echo $_SESSION['s_name'].'d';*/ header("Location: login.php"); } ?> PHP: Any help would be appreciated. Thanks in advance
The sql query isnt returning anything, try printing the $results out to see what you get. I think the query might be wrong?
Hi I know this is a very old thread. I have replied that for the all future visitors with a view to helping them: see below: $result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId"); Cart is table name here. I know that when table name is too short and without underscore thn mql shows the error. because mysql can not detect short name. when table name is too short and without underscore thn you must have to add ` both side of the table name in query. Or if u dont want to add ` thn select a name with a underscore or select a long name. See example and try below one and both will work : $result = mysql_query("select count(*) from `cart` where cookieId = '" . GetCartId() . "' and itemId = $itemId"); or, $result = mysql_query("select count(*) from cart_1 where cookieId = '" . GetCartId() . "' and itemId = $itemId");