Thread: Need help
View Single Post
12-18-2012, 05:54 PM
#2
newkid is offline newkid
Status: Junior Member
Join date: Sep 2006
Location:
Expertise: PHP,MySQL, HTML(5), CSS
Software: Photoshop, Sublime Text2,MS VS
 
Posts: 63
iTrader: 1 / 100%
 

newkid is on a distinguished road

Send a message via Skype™ to newkid

  Old

You are concatenating your query string improperly. You are also missing quotes for the values. All strings should be enclosed in quotes for SQL except for numerical values.

rewrite your query string so that it becomes

$query="Update users set USERNAME='". $username ."', PASSWORD='". $password ."', FIRSTNAME='". $firstname ."', LASTNAME='". $lastname ."', EMAIL='". $email ."', ACCOUNTSTATUS='". $accountstatus."' where CODE='". $CODE."'";

I would advise you to do the following steps to help you understand and get better at concatenating long strings like above:

1) Write the string placeholders instead of variables without any cancatenations

ie $query="Update users set USERNAME='username', PASSWORD='password', FIRSTNAME='firstname', LASTNAME='lastname', EMAIL='email', ACCOUNTSTATUS='accountstatus' where CODE='CODE'";

2) replace each placeholder with ". ." (including quotations) or '. .' if you are using single quotations for your string and enter the correct variable. Do this for each place holder at a time.

This
$query="Update users set USERNAME='username', PASSWORD='password',...

becomes
$query="Update users set USERNAME='". $username ."', PASSWORD='password',...

then
$query="Update users set USERNAME='". $username ."', PASSWORD='". $password ."',...

This method will train you to do it correctly. It may seem annoying at first but once you get the hang of it, you will be able to do make similar strings without having to write the whole string first.

Hope this helps.

Reply With Quote