Jump to content

Using Query String Variables in DB Query


neridaj

Recommended Posts

Hey people,

 

I'm trying to use a query string variable in a sql query but can't figure out how to make it work. I've tried escaping quotes, using double quotes and no quotes at all but nothing seems to work. Here is what I have:

 

/*

 

$pt = $_GET['pt'];

$rndtitle = 'select painting_title from paintings where painting_year =' . echo $pt . 'order by rand() limit 1;';

 

*/

 

Is there a better way to do this?

 

Thanks,

 

Jasn

Link to comment
https://forums.phpfreaks.com/topic/84348-using-query-string-variables-in-db-query/
Share on other sites

Thanks for the reply, but unfortunately it didn't work. I thought that would be the solution as well, as I had previously replaced the single quotes with doubles, but it doesn't work no matter which quotes you change. Thanks for the "SQL injection" heads up, I'm obviously still new to PHP/MySQL so I need to read up cleaning my  variable and mysql_real_escape_string().

 

Cheers,

 

Jason

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.