Jump to content

Recommended Posts

I'm storing mysql queries in a database. I want to store the $_GET key in my query so that when I pull the query from the db it replaces '$_GET['id']' with whatever the value happens to be, eg

 

$sql = "SELECT * FROM users WHERE user_id =  ".$_GET['id']

 

I serialize the data before it's entered into the db as the qury is part of an array of data. I just can't work out the proper format. It's fine when I don't have a dynamic variable inside the query.

 

Any help will be much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/202014-serialize-global-keys-_get-var/
Share on other sites

Yeah that's normal behaviour, PHP only sees the query as a string of text and so doesn't parse the variable. When you actually execute the query do you know which you're parsing or are they run in some form of loop? I'm thinking you could replace variables with '%s' and use sprintf to add the dynamic values..?

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.