Retrieving data from database
Posted: Tue Nov 03, 2009 4:23 pm
Hi guys
I have a database with fields 'a', 'b', 'c' and 'd'. I want to retrieve info from the database and display it using a form where the info in fields a, b, c or d equals the info selected in the form. I have the following php code and form to achieve this:
PHP code:
HTML form
My problem is that when i execute the form all records in the database are being retrieved regardless of whether the database field has the required data.
I've looked into what may be going wrong without success.
Any heads up on what may be going wrong would be greatly appreciated.
Many thanks.
I have a database with fields 'a', 'b', 'c' and 'd'. I want to retrieve info from the database and display it using a form where the info in fields a, b, c or d equals the info selected in the form. I have the following php code and form to achieve this:
PHP code:
Code: Select all
if ($_POST['xyz']) {
$x = trim($_POST['xyz']);
} else {
$errors[] = '<small id="error">Error</small>';
}
// Make the query:
$q = "SELECT CONCAT(first_name, ' ', last_name) AS name, (email) FROM users
WHERE a OR b OR c OR d = '$x'";
$r = @mysqli_query ($dbc, $q); // Run the query.
if ($r) { // If it ran OK, display the records.
// Table header.
echo 'display data';Code: Select all
<select name="xyz" class="input"/>
<option value="something1">XXX</option>
<option value="something2">XXX</option>
</select>I've looked into what may be going wrong without success.
Any heads up on what may be going wrong would be greatly appreciated.
Many thanks.