baldiajaib Posted June 20, 2011 Share Posted June 20, 2011 I followed a pagination tutorial in PHPFreaks...edited it using my own preference and this error comes out Notice: Undefined index: name in C:\xampp\htdocs\guestbook\index.php on line 105 Notice: Undefined index: url in C:\xampp\htdocs\guestbook\index.php on line 106 Notice: Undefined index: email in C:\xampp\htdocs\guestbook\index.php on line 107 Notice: Undefined index: message in C:\xampp\htdocs\guestbook\index.php on line 108 Notice: Undefined index: date in C:\xampp\htdocs\guestbook\index.php on line 109 Thanks for reading guys...really appreciate your help <?php ob_start(); ///*//Error reporting $ebits = ini_get('error_reporting'); error_reporting($ebits ^ E_NOTICE); //*/ // Connect to the MySQL database include "scripts/connect_to_mysql.php"; // Sends data to database = GUESTBOOK if (isset($_POST['submit'])) { $name = mysql_real_escape_string($_POST['guest_name']); $email = mysql_real_escape_string($_POST['guest_email']); $url = mysql_real_escape_string($_POST['guest_url']); $message = mysql_real_escape_string($_POST['guest_message']); // See if that e-mail is an identical match to another e-mail in the system $sql = mysql_query("SELECT email FROM guestlist WHERE email='$email' LIMIT 1"); $productMatch = mysql_num_rows($sql); if ($productMatch > 0) { echo 'Sorry, e-mail already registered, <a href="index.php">click here</a>'; exit(); } // Store data into the database $sql = mysql_query("INSERT INTO guestlist (name, email, url, message, ip, date) VALUES('$name','$email','$url','$message', '$guest_ip', now())") or die (mysql_error()); $pid = mysql_insert_id(); // Place image in the folder $newname = "$pid.png"; move_uploaded_file( $_FILES['file']['tmp_name'], "image/$newname"); header("location: index.php"); exit(); } //Retrieve guest's IP address $ipaddress=$_SERVER["REMOTE_ADDR"]; echo "Your IP ADDRESS: ". $ipaddress; // --------------------------------------------------PAGINATION--------------------------------------------------------------------------- // database connection info include "scripts/connect_to_mysql.php"; // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM guestlist"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 10; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db // while there are rows to be fetched... // Display guest list from database $guest_list = ""; $result2 = mysql_query("SELECT id FROM guestlist LIMIT $offset, $rowsperpage"); $productCount2 = mysql_num_rows($result2); echo "<br/>".$productCount2; if ($productCount2 > 0) { while($row = mysql_fetch_array($result2)){ $id = $row["id"]; $name = $row["name"]; $url = $row["url"]; $email = $row["email"]; $message = $row["message"]; $date = strftime("%b %d, %Y", strtotime($row["date"])); // Generate list into a organized table $guest_list .= "<tr> <td style=\"width:200px\" rowspan=\"3\"> <img src=\"image/" . $id . ".png\" alt=\"' . $name . '\" width=\"120\" border=\"0\" /></td> </tr> <tr> <td style=\"width:280px\"><strong><font size=\"2\">$name</font></strong><br/> <font size=\"1\">$email</font><br/> <font size=\"1\"><a href=\"$url\">$url</a></font><br/> <em><font size=\"1\"><p align=\"left\"> <font size=\"1\"><p align=\"left\">Added $date</p></font></em></td> <td style=\"width:700px\" align=\"center\"> $message </td></tr><br /> <tr> <td style=\"width:200px\"></td> <td style=\"width:700px\"></td></tr>"; } } else { $guest_list = '<div style="font-family:verdana,arial,helvetica;color:#FFFFFF;">Guest List is Empty! No one visited you!</font>'; } /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?> <!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=utf-8" /> <title>Guestbook v1.0</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" /> <script type="text/javascript" language="javascript"> function validateMyForm ( ) { var isValid = true; if ( document.guestbook.guest_name.value == "" ) { alert ( "Please type your Name" ); isValid = false; } else if ( document.guestbook.guest_email.value == "" ) { alert ( "Please type your Email" ); isValid = false; } else if ( document.guestbook.guest_url.value == "" ) { alert ( "Please type your URL" ); isValid = false; } else if ( document.guestbook.guest_message.value == "" ) { alert ( "Please type your message" ); isValid = false; } return isValid; } </script> </head> <body> <div align="center" id="head" name="head"> <h1> GUESTBOOK </h1> </div> <div align="center"> <h2><em>Guest list</em></h2> </div> <table border="0" align="center" id='table2' name='table2'> <?php echo "<font color=\"#000000\" size=\"2px\">$guest_list</font>"; ?> </table> </br></br> <div id="body" name="body" align="center"> <form enctype="multipart/form-data" action="index.php" name="guestbook" id="guestbook" method="post"> <table align="center" width="90%" cellpadding="6" cellspacing="0" id="table" name="table"> <tr> <td> <div align="right">Name:</div></td> <td> <input type="text" name="guest_name" id="guest_name" size="50" /></tr> <tr> <td> <div align="right">E-Mail:</div></td> <td> <input type="text" name="guest_email" id="guest_email" size="50" /></tr> <tr> <td> <div align="right">URL:</div></td> <td> <input type="text" name="guest_url" id="guest_url" size="50" /></tr> <tr> <td> <div align="right">Photo:</div></td> <td><label> <div align="left"> <input type="file" name="file" id="file" /> <!-- <font size="1"><i>(Limit upload of 120px X 120px)</i></font>--> </div> </label></tr> <tr> <td> Message:</td> <td> <div align="left"> <textarea name="guest_message" id="guest_message" cols="40" rows="10"></textarea> </div></td> </tr> <tr><td></td> <td> <div align="left"> <input type="submit" name="submit" id="submit" value="Submit" onclick="javascript:return validateMyForm();" /> </div></td></tr> </table> </form> </div> </body> <?php ob_flush(); ?> </html> Quote Link to comment https://forums.phpfreaks.com/topic/239843-items-from-db-did-not-appear-notice-undefined-index/ Share on other sites More sharing options...
baldiajaib Posted June 20, 2011 Author Share Posted June 20, 2011 $result2 = mysql_query("SELECT id FROM guestlist LIMIT $offset, $rowsperpage"); Correction: $result2 = mysql_query("SELECT * FROM guestlist LIMIT $offset, $rowsperpage"); thanks for reading guys...solved it Quote Link to comment https://forums.phpfreaks.com/topic/239843-items-from-db-did-not-appear-notice-undefined-index/#findComment-1232009 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.