Jump to content

does this need single quote?


zgkhoo

Recommended Posts

	$sql="INSERT INTO person (UserID,Username,Password,Level,Country,IC,FullName,Gender,DOB,Address,Postcode,City,State,PhoneNumber,HpNumber,BankType,AccName,AccNumber,Acctstatus)
	VALUES ($UID,'$_SESSION[username]','$_SESSION[password]','User','$_SESSION[country]',
         '$_SESSION[ic]','$_SESSION[fullname]','$_SESSION[gender]','$_SESSION[dob]',
	 '$_SESSION[address]','$_SESSION[postcode]','$_SESSION[city]','$_SESSION[state]',
	 '$_SESSION[phonenumber]','$_SESSION[hpnumber]','$_SESSION[banktype]',
	 '$_SESSION[accname]','$_SESSION[accnumber]','Active')";

 

$UID in the above code, need single quote or not?

Link to comment
https://forums.phpfreaks.com/topic/75910-does-this-need-single-quote/
Share on other sites

If mysql comes across an unquoted string value

 

eg

SELECT * FROM tablename WHERE username = zgkhoo

 

It makes the following assumptions

 

1 ) tablename must be a table name as it is in the FROM clause.

 

2 ) username and zgkhoo are column names.

 

You will then get an error message saying "column zgkhoo does not exist".

 

To prevent string values from being interpreted as column names they are put inside single quotes

 

eg

SELECT * FROM tablename WHERE username = 'zgkhoo'

 

Column names cannot be numeric so this is not the case with numbers

 

eg

SELECT * FROM tablename WHERE id = 5

 

Here there is no ambiguity so no quotes are required (although mysql will not object to '5')

 

 

There is an apparent exception the this rule in the ORDER BY clause. If you have

SELECT cat_id, cat_name FROM category ORDER BY 2

then it will order the output by cat_name, the 2nd column selected.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.