Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

php where clause


  • Please log in to reply

#1
outatime88

outatime88

    Member

  • Member
  • PipPip
  • 39 posts
I need to know how I can make the where clause point to what someone searches for in a form. Here is what I'm talking about:

$result = mysql_query("SELECT * FROM info WHERE City=''");

I have a column named City in my mysql db. I want to know what I need to put in there to make it look for what someone searches for.

thanks

Edited by outatime88, 28 December 2006 - 10:07 AM.

  • 0

Advertisements


#2
Michael

Michael

    Retired Staff

  • Retired Staff
  • 1,869 posts
Well I would guess you would have an input box like this in a forum

<form method="post" action="something.php">
<input type="text" name="city">
<input type="submit" value="Submit">
</form>

And the php would be like this.

$city = $_POST['city'];

$result = mysql_query("SELECT * FROM info WHERE City LIKE '$city'");

I use the LIKE because then CITY is the same as city if you know what I mean.
  • 0

#3
outatime88

outatime88

    Member

  • Topic Starter
  • Member
  • PipPip
  • 39 posts
hey michael, that worked great thanks a lot.
  • 0

#4
Michael

Michael

    Retired Staff

  • Retired Staff
  • 1,869 posts
Opps I forgot something important, you should do this

$city = mysql_real_escape_string($_POST['city']);

This stops the input being treated as part of the MySql string. Someone with bad intent could do some damage other wise.

I should remember not to post when I am tired :whistling:
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP