Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,255
Total Threads: 81,222
Total Posts: 566,958
There are 179 users currently browsing (tf).
  Our Partners:
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Need help

Thread title: Need help
    Thread tools Search this thread Display Modes  
12-18-2012, 09:34 AM
ervisballa is offline ervisballa
Status: I'm new around here
Join date: Dec 2012
Posts: 1
iTrader: 0 / 0%

ervisballa is on a distinguished road

  Old  Need help

I receive an error in my line of code, any help please


Here give me error
$query="Update users set USERNAME=".$username,"PASSWORD=".$password,"FIRSTN AME=".$firstname,"LASTNAME=".$lastname,"EMAIL=".$e mail,"ACCOUNTSTATUS=".$accountstatus,"where CODE="$code"";

mysql_query($query) or die ('Gabim');

Reply With Quote
12-18-2012, 05:54 PM
newkid is offline newkid
Status: Junior Member
Join date: Sep 2006
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


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.

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

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

$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
12-18-2012, 06:01 PM
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
Posts: 6,893
iTrader: 18 / 100%

Village Genius will become famous soon enough


Be very careful doing this, that code is vulnerable to SQL injection attacks.

Reply With Quote

Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed