By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

Thanks,
Oliver

Jan 27 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi

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' =>
'address_table_date_field');

$stmt = 'select * from users where '.$dateFields['users'].' =
'.cleanUp($_GET['date']);

[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.]

HTH

-Kurt

On Jan 27, 7:41 am, "McGowan" <Boome...@gmail.comwrote:
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.

Thanks,
Oliver
Jan 28 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.