Jump to content

Searching with Get


underknown

Recommended Posts

I'm having some trouble with a GET search code; everything works until the stringresult but then it dies to Error Querying Database

<html>
<body>

<?php

//Get sort setting and search terms from URL with GET
$usersearch = $_GET['usersearch'];
echo 'Search word: ' . $usersearch;
echo '<br>';
require_once("dbvars.php");

//Connect to Database
$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PW, DB_NAME) or die ("Error connecting to database.");

//Build the Query
$query = "SELECT * FROM customers" . 'WHERE customers.given_name=\'' . $usersearch . '\'';
echo $query;

//Execute the Query
$result = mysqli_query($dbc, $query) or die ("Error querying database.");

//Create the Table Headings
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>';
echo '</tr>';

//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></tr>';
}
'</table>';

// Close the database connection
mysqli_close($dbc);

?>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input name="usersearch" type="text" size="30" />
<input name="submit" type="submit" value="go" />
</form>

</body>
</html>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.