Jump to content

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

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.