php + mysql. updating various tables using the same peice of code.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hey, I'm wondering how I can get an update statement to work with data  
being passed through the URL. the problem is that the statement needs  
to work no matter what table is being worked on as any table must be  
able to be processed by the same page.

The problem is that I can't use $_GET['field_name'] because I dont  
know what the field name is going to be. Also I do not know what field  
is going to be the primary key so I don't know how to get the 'where'  
statement to work properly.

I realise there are probably tens if not hundreds of ways of making  
this work but I honestly can't do it.


Re: php + mysql. updating various tables using the same peice of code.


While I'm not entirely sure I understand your issue, it seems like  
there are a couple of possibilities:
1) Give the date field in every table the same name (which can be  
confusing unless they have the same purpose; however, having an  
"updated" timestamp field in every table can be handy to know when a  
record was last updated).
2) Have an associative array that maps from table name to date field  
name. So, depending on the table you are using, you get the name of  
the date field from the array, like:
$dateFields = array('users' => 'user_table_date_field', 'addresses' =>  

$stmt = 'select * from users where '.$dateFields['users'].' =  

[The "cleanUp()" function is not really part of the discussion...I  
just wanted to make sure you are checking the input for Bad Stuff  
before using it in a query, as anyone can put anything in the GET.]



Quoted text here. Click to load it

Site Timeline