Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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