Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to pass variable to a mySql query 1

Status
Not open for further replies.

elentz

Technical User
Jan 9, 2007
81
US
I have a simple form with one input. I have a $_get Method set up. When the user hits enter the browser refreshes and goes to my second page with the variable name added to the url. So far so good, to test it I made a small page to show That the make sure I could GET the variable, and that worked. Now I need to get that variable into the Where clause of a MSql query. Can someone help me out here? I just can't get it to work. Can someone give me a couple of example??

Thanks
 
Suppose your variable is called mygetvar, you could create a query thus:

Code:
$myvar=$_GET['mygetvar'];
$query="SELECT * FROM table WHERE field='$myvar' ";

 
make sure that you validate and escape all variables that you use in your query and that derive from an untrusted source.
 
Thank you guys!! I found two problems, I was using the same variable name in both the forms for the variable I was trying to get from one to another. And second I used phpmyadmin to make the PHP code for me and my query, it had ALOT of ' and , in the query, I cleaned some of them out and it works fine

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top