Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1414 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Need help

Thread title: Need help
Reply    
    Thread tools Search this thread Display Modes  
12-18-2012, 09:34 AM
#1
ervisballa is offline ervisballa
Status: I'm new around here
Join date: Dec 2012
Location:
Expertise:
Software:
 
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


$code=$_REQUEST['CODE'];
$username=$_REQUEST['USERNAME'];
$password=$_REQUEST['PASSWORD'];
$firstname=$_REQUEST['FIRSTNAME'];
$lastname=$_REQUEST['LASTNAME'];
$email=$_REQUEST['EMAIL'];
$accountstatus=$_REQUEST['ACCOUNTSTATUS'];

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
#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
12-18-2012, 06:01 PM
#3
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,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

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

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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