View Full Version : Is this valid code?

09-18-2003, 04:31 PM
Im trying to get it to make my query based on varibles passed in a form, however im getting a parse error with this code. Can you use the $_GET method inside a query like this? What did i do wrong?

$query1 = "INSERT into customer(cust_name, case_id, notebook_model, notebook_serial, capture, error_msg) VALUES
("$_GET['customer']", "$_GET['case_id']", "$_GET['notebook_model']", "$_GET['notebook_serial']", "$_GET['capture']", "$_GET['error_msg']")";

Parse error: parse error, unexpected T_VARIABLE in c:\inetpub\wwwroot\hdd-form.php on line 20

thanks guys!

09-18-2003, 05:33 PM
('$_GET[customer]', '$_GET[case_id]', '$_GET[notebook_model]', '$_GET[notebook_serial]', '$_GET[capture]', '$_GET[error_msg]')

09-18-2003, 06:29 PM
Thanks! i couldnt figure out what i had done wrong :/

09-18-2003, 07:07 PM
nitpicking I know ;) but that should be ...

('{$_GET['customer']}', '{$_GET['case_id']}', '{$_GET['notebook_model']}', '{$_GET['notebook_serial']}', '{$_GET['capture']}', '{$_GET['error_msg']}')


('" . $_GET['customer'] . "' , '" . $_GET['case_id'] //etc for older PHP versions

09-18-2003, 09:45 PM
You know its funny you say that, i was searching my arse off trying to figure out what i was doing wrong and i came across something that was on PHP.net under the $foo[bar]; tutorial for arrays and they showed the example you did with the {}

At least now i know the correct way... thanks again

09-18-2003, 09:53 PM
Just to confuse the hell out of you,

$query1 = "INSERT into customer(cust_name, ...) VALUES ('$_GET[customer]', ...)";

should work as Nightfire showed already, your initial problem was incorrect nesting of quotes. Single quotes within double quotes aren't a problem though.