Jump to content

Serialize global keys $_GET var


php_fish

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..?

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.