roldahayes Posted September 17, 2008 Share Posted September 17, 2008 can anyone help with why this only returns a blank page please: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <SCRIPT language="JavaScript"> function confirmDelete(id) { if (confirm("Are you sure you wish to delete this?")) { window.location.href = "deleteItem.php?id=" + id; } } //--> </SCRIPT> <title>List</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <link href="../css/admin.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>List</h1> <p><a href="newItem.php">Add new item</a></p> <form action="index.php" method="post"> <p>Search:<input type="text" name="searchtext" /></p> <input type="submit" value="Search" /> </form> <?php // function to make connection to MySQL database include('../dbcnt.php'); $db_conn = db_connect(); // database connection // The basic SELECT statement $select = 'SELECT DISTINCT id, sup_name, sup_address, sup_postcode, sup_postcode_2, sup_telephone'; $from = ' FROM suppliers'; $where = ' WHERE 1=1'; $searchtext = $_POST['searchtext']; if ($searchtext != '') { // Some search text was specified $where .= " AND (sup_name LIKE '%$searchtext%' OR sup_address LIKE '%$searchtext%' OR sup_postcode LIKE '%$searchtext%' OR sup_postcode_2 LIKE '%$searchtext%' OR sup_telephone LIKE '%$searchtext%')"; } ?> <table> <tr><th>No.</th><th>Name</th><th>Address</th><th>Postcode</th><th>Telephone</th><th>Options</th></tr> <?php $suppliers = @mysql_query($select . $from . $where ); if (!$suppliers) { echo '</table>'; exit('<p>Error retrieving suppliers from database!<br />'. 'Error: ' . mysql_error() . '</p>'); } while ($supply = mysql_fetch_array($suppliers)) { echo "<tr valign='top'>\n"; $id = $supply['id']; $sup_name = htmlspecialchars($supply['sup_name']); $sup_address = htmlspecialchars($supply['sup_address']); $sup_postcode = htmlspecialchars($supply['sup_postcode']); $sup_postcode_2 = htmlspecialchars($supply['sup_postcode_2']); $sup_telephone = htmlspecialchars($supply['sup_telephone']); echo "<td>$id</td>\n"; echo "<td>$sup_name</td>\n"; echo "<td>$sup_address</td>\n"; echo "<td>$sup_postcode $sup_postcode_2</td>\n"; echo "<td>$sup_telephone</td>\n"; echo "<td><a href='editItem.php?id=$id'>Edit</a> | " . "<a href='javascript:confirmDelete($id)'>Delete</a></td>\n"; echo "</tr>\n"; } ?> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/124653-error-in-this-code/ Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 Possibly something in your CSS file. Can you list what's in that? Link to comment https://forums.phpfreaks.com/topic/124653-error-in-this-code/#findComment-643820 Share on other sites More sharing options...
stublackett Posted September 17, 2008 Share Posted September 17, 2008 Put this in your code <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); ?> It looks like your hosting co have disabled PHP Errors Link to comment https://forums.phpfreaks.com/topic/124653-error-in-this-code/#findComment-643821 Share on other sites More sharing options...
roldahayes Posted September 17, 2008 Author Share Posted September 17, 2008 I think i may have narrowed it down to // function to make connection to MySQL database include('../dbcnt.php'); if i insert the coneection settings into the page it works... Link to comment https://forums.phpfreaks.com/topic/124653-error-in-this-code/#findComment-643834 Share on other sites More sharing options...
roldahayes Posted September 17, 2008 Author Share Posted September 17, 2008 with errors on I'm getting this Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'username'@'localhost' (using password: YES) in /home/default/test.viewmykitchen.com/user/htdocs/dbcnt.php on line 11 I cannot connect to the database because: Access denied for user 'username'@'localhost' (using password: YES) Link to comment https://forums.phpfreaks.com/topic/124653-error-in-this-code/#findComment-643836 Share on other sites More sharing options...
roldahayes Posted September 17, 2008 Author Share Posted September 17, 2008 okey dokey... Sort out the connection problem.... Now getting this error Notice: Undefined index: searchtext in /home/default/test.viewmykitchen.com/user/htdocs/admin/index.php on line 41 line 41 is here: // The basic SELECT statement $select = 'SELECT DISTINCT id, sup_name, sup_address, sup_postcode, sup_postcode_2, sup_telephone'; $from = ' FROM suppliers'; $where = ' WHERE 1=1'; $searchtext = $_POST['searchtext']; if ($searchtext != '') { // Some search text was specified $where .= " AND (sup_name LIKE '%$searchtext%' OR sup_address LIKE '%$searchtext%' OR sup_postcode LIKE '%$searchtext%' OR sup_postcode_2 LIKE '%$searchtext%' OR sup_telephone LIKE '%$searchtext%')"; } Link to comment https://forums.phpfreaks.com/topic/124653-error-in-this-code/#findComment-643843 Share on other sites More sharing options...
adam291086 Posted September 17, 2008 Share Posted September 17, 2008 thats basically saying there is no information from the $_POST['searchtext']; Link to comment https://forums.phpfreaks.com/topic/124653-error-in-this-code/#findComment-643846 Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 Your post variable isn't set. Maybe change the if statement like this: $searchtext = $_POST['searchtext']; if (isset($_POST['searchtext'])) { // Some search text was specified $searchtext = $_POST['searchtext']; $where .= " AND (sup_name LIKE '%$searchtext%' OR sup_address LIKE '%$searchtext%' OR sup_postcode LIKE '%$searchtext%' OR sup_postcode_2 LIKE '%$searchtext%' OR sup_telephone LIKE '%$searchtext%')"; } Link to comment https://forums.phpfreaks.com/topic/124653-error-in-this-code/#findComment-643847 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.