I’m trying to update certain columns in MYSQL database with PHP, but they are spaced apart, with other columns of information in between.
full database $query -
(join_date, last_updated, username, pass_word, first_name, last_name, email, gender, dob, city, state, country, bit_about_me, profile_pic)
those I want to update in the $query -
(last_updated, first_name, last_name, email, gender, dob, city, state, country, bit_about_me, profile_pic)
Please notice the removal of ‘username, pass_word’ in between ‘last_updated’ and ‘first_name’.
The question I have is:
how do I write the code in PHP to update certain columns in my database when they are spaced apart?
Do I:
A. write out in the $query the entire outline of the database, but only update certain parts through accessing certain variables in the form?
or
B. write out ONLY the columns I wish to update in the $query, separating them through commas, AND, individual SET etc?
Immediate follow-up question:
IF I have to put the whole database outline in the $query, what do I put in the columns where I don’t want new information to be inputted?
Note: I have tried using UPDATE with SET having all columns = $variables with a comma separating each column; [php]$query = “UPDATE Users SET last_updated = NOW(), first_name = ‘$first_name’, last_name = ‘$last_name’, email = ‘$email’, gender = ‘$gender’, dob = ‘$dob’, city = ‘$city’, state = ‘$state’, country = ‘$country’, bit_about_me = ‘$bit_about_me’, profile_pic = ‘$profile_pic’ WHERE gamertag =” . $_SESSION[‘gamertag’];[/php]
I have also used AND after removing the command in between each column;[php]$query = “UPDATE Users SET last_updated = NOW() AND first_name = ‘$first_name’ AND last_name = ‘$last_name’ AND email = ‘$email’ AND gender = ‘$gender’ AND dob = ‘$dob’ AND city = ‘$city’ AND state = ‘$state’ AND country = ‘$country’ AND bit_about_me = ‘$bit_about_me’ AND profile_pic = ‘$profile_pic’ WHERE gamertag =” . $_SESSION[‘gamertag’];[/php]
I understand I may still be able to use either or, but with a different $query outline;
Any help, tips, advice, or information on this would be greatly appreciated.
-ECP03