underknown Posted October 30, 2010 Share Posted October 30, 2010 Alright, I'm supposed to be creating a search bar, but I keep running into errors, and I'm sure there must be something wrong here that I'm missing. I don't know whether it's the PHP or the HTML that's messing up, so I apologize for that, but given the nature of the errors, I'd assume the former. Here's the code: <?php include("header.php"); ?> <?php include("topmenu.php"); ?> <?php include("menu.php"); ?> <?php include("news.php"); ?> <?php include("links.php"); ?> <?php include("info.php"); ?> <!-- **** php include news.php, links.php and info.php here to return side menu --> <div id="column2"> <h1>introduction</h1> <!-- **** INSERT PAGE CONTENT HERE **** --> <div id="content"> <li><a id="various3" href="http://localhost/website/center.php">Add Customers</a></li> </ul> </div> <br /> <?php echo "Customer Results from Database"; require_once("dbvars.php"); //Search if (isset($_POST['search'])) { $name = $_POST['name']; $name_trimmed = trim($name); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME) or die('Error connecting to database.'); $query = "SELECT * FROM customers WHERE name LIKE '%$name_trimmed%'"; $result = mysqli_query($dbc, $query) or die('Error querying database.'); mysqli_close($dbc); echo '<h1>Search Results</h1>'; echo '<table border="0\"><tr>'; echo '<td><b>First Name</b></td>'; echo '<td><b>Last Name</b></td>'; echo '<td><b>Address</b></td>'; echo '<td><b>City</b></td>'; echo '<td><b>Province</b></td>'; echo '<td><b>Postal Code</b></td>'; echo '<td><b>Phone Number</b></td>'; While ($row = mysqli_fetch_array($result)) { echo '<tr><td>' . $row['given_name'] . '</td>'; echo '<td>' . $row['surname'] . '</td>'; echo '<td>' . $row['address'] . '</td>'; echo '<td>' . $row['city'] . '</td>'; echo '<td>' . $row['province'] . '</td>'; echo '<td>' . $row['postal_code'] . '</td>'; echo '<td>' . $row['phone_number'] . '</td>'; } } // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME) or die('Error connecting to MySQL server.'); // Build the query $query = "SELECT * FROM customers"; $result = mysqli_query($dbc, $query) or die('Error querying database.'); //Table Headers echo '<table border="1\"><tr>'; echo '<td><b>First Name</b></td>'; echo '<td><b>Last Name</b></td>'; echo '<td><b>Address</b></td>'; echo '<td><b>City</b></td>'; echo '<td><b>Province</b></td>'; echo '<td><b>Postal Code</b></td>'; echo '<td><b>Phone Number</b></td>'; //Display Results through Array Loop While ($row = mysqli_fetch_array($result)) { echo '<tr><td>' . $row['given_name'] . '</td>'; echo '<td>' . $row['surname'] . '</td>'; echo '<td>' . $row['address'] . '</td>'; echo '<td>' . $row['city'] . '</td>'; echo '<td>' . $row['province'] . '</td>'; echo '<td>' . $row['postal_code'] . '</td>'; echo '<td>' . $row['phone_number'] . '</td>'; } '</table>'; // Close the database connection mysqli_close($dbc); ?> <!-- Search Form --> <div class="form" /> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" /> <input name="name" id="name" type="text" value="enter name" size="30" maxlength="50" /> <div class="button"> <input name="search" type="submit" value="go" /> </div> </form> </div> <div style="clear:both"> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/217318-search/ Share on other sites More sharing options...
underknown Posted October 30, 2010 Author Share Posted October 30, 2010 Nevermind, I found the issue. Link to comment https://forums.phpfreaks.com/topic/217318-search/#findComment-1128460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.