Jump to content

sql query problems


adult.swim

Recommended Posts

I have created a html form page, and a corresponding process page.

My form gets input from the user, and compares it to the fields in my database. If the input

in the form matches a field in the dB, the process page returns the corresponding record.

The problem is only the address input for the form works correctly. All of the other fields

return all the records in the dB. I've tried varying the SQL query code many times.

My question is why does only the address search work as opposed to the other input fields?

search.php: form

[code]

<form id=\"search\" method=\"post\" action=\"process.php\">

<table class=\"search1\">

<tr>
<th><label for=\"pad\">Pad Number</label></th>
<td><input id=\"pad\" name=\"pad\" type=\"text\" class=\"inputbox\" size=\"50\" /><br

/></td>
</tr>

<tr>
<th><label for=\"mls\">MLS Number</label></th>
<td><input id=\"mls\" name=\"mls\" type=\"text\" class=\"inputbox\" size=\"50\" /><br

/></td>
</tr>

<tr>
<th><label for=\"address1\">Address</label></th>
<td><input id=\"address1\" name=\"address1\" type=\"text\" class=\"inputbox\" size=\"100\"

/><br /></td>
</tr>

<tr>
<th><label for=\"city\">City</label></th>
<td><input id=\"city\" name=\"city\" type=\"text\" class=\"inputbox\" size=\"100\" /><br

/></td>
</tr>

<tr>
<th><label for=\"zip\">Zip Code</label></th>
<td><input id=\"zip\" name=\"zip\" type=\"text\" class=\"inputbox\" size=\"15\" /><br

/></td>
</tr>


</table>

<br />

<table class=\"search2\">

<tr>
<td>

<input type=\"Submit\" value=\"Submit\" style=\"width: 60px; font-size: 1.0em; padding: 2px

10px 2px 10px; margin: 5px 3px -3px 3px; background-color: #115492; float: left; border:

solid 1px #023666; color: #ffffff; text-decoration: none;\" />

<input type=\"Reset\" value=\"Reset\" style=\"width: 60px; font-size: 1.0em; padding: 2px

10px 2px 10px; margin: 5px 3px -3px 3px; background-color: #115492; float: left; border:

solid 1px #023666; color: #ffffff; text-decoration: none;\" />

<input type=\"hidden\" name=\"op\" value=\"do\" /><p>&nbsp;</p>
</td>
</tr>
</form>

</table>

[/code]

---------------------------------------------
process.php:

[code]
<?
# connect to a DSN "mydb" with a user and password "marin"
$connect = odbc_connect("**", "**", "**");

# query the users table for name and surname
$query = "SELECT * FROM props WHERE props.MLSnumber='$mls'
OR props.Pads LIKE '%$pad%'
OR props.Address LIKE '%$address1%'
OR props.City='$city'
OR props.Zip='$zip'";

# perform the query
$result = odbc_exec($connect, $query);

//output results to standard output
//odbc_result_all($result, "BORDER=1");

# fetch the data from the database
while(odbc_fetch_row($result)){
  $mls = odbc_result($result, 2);
  $address = odbc_result($result, 5);
  $pad = odbc_result($result, 16);
  $city = odbc_result($result, 7);
  $zip = odbc_result($result, 9);
  $check = odbc_result($result, 17);
//  print("$mls  $address  $pad  $city  $zip");
 
  //format results
    print ("<tr>");
    print ("<td>$pad</td>");
    print ("<td>$mls</td>");
    print ("<td>$address</td>");
print ("<td>$city</td>");
print ("<td>$zip</td>");
print ("</tr>");
    }

# close the connection
odbc_close($connect);
?>

[/code]
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.