Forum Moderators: coopster
I've been working on a recent PHP/SQL project and ran into a bit of a snag.
Regularly I'll be updating some fields in the table, but not all of them. I didn't want to list input fields for every field in the table on a page if I didn't have to. I also did not want to write queries for each and every field.
I thought that maybe I'd be able to use a drop-down menu and an input field. The selected item on the drop down menu would equal the field in the database, and the input field would equal the new variable for the field in the table.
I tried several variations on an update query, specifically:
mysql_query("UPDATE table SET $dropdown='$input'");
It hasn't been successful, mainly for the fact that I can't get the code to recognize $dropdown as anything other than an actual field name itself, and not a variable. Of course the script stops as soon as it finds there's no field named $dropdown.
IF this makes sense to anyone, and if anyone can confirm whether or not this is even possible, please let me know.
Thanks,
A.Guy
Right now, that particular section of code looks like:
if ($dropdown && $inputtext!= null) {
mysql_query("UPDATE table SET '".$dropwodwn."'='$inputtext'");
}
I didn't make the adjustments to the inputtext variable because that's the way all of my other variables have been entered up to this point and they have been working fine in queries without dynamic field names.