Page 1 of 1

PHP parse error, please help!!

Posted: Wed Jan 26, 2005 5:16 am
by mhouldridge
Hi,

This is the error I get when trying to update the dedicated set for my database;

Parse error: parse error, unexpected '=' in C:\Audit\postupdate.php on line 26

Here is the code;

<?php
foreach($HTTP_POST_VARS as $varname => $value)
$formVars[$varname]=$value;
$db = mysql_connect("localhost","giacom-admin","snooker") or die("Problem connecting");
mysql_select_db("audit") or die("Problem selecting database");
echo "Record updated<br><a href=\"update.php\">click here</a> to update another record<br>";
query="UPDATE dedicated set ".
"title= \"".$formVars["title"]."\",".
"customer= \"".$formVars["customer"]."\",".
"type= \"".$formVars["type"]."\",".
"serial= \"".$formVars["serial"]."\",".
"os= \"".$formVars["os"]."\",".
"oslicense= \"".$formVars["oslicense"]."\",".
"oemfull= \"".$formVars["oemfull"]."\",".
"processor= \"".$formVars["processor"]."\",".
"memory= \"".$formVars["memory"]."\",".
"IP= \"".$formVars["IP"]."\",".
"disksize= \"".$formVars["disksize"]."\",".
"graphics= \"".$formVars["graphics"]."\",".
"networkcard= \"".$formVars["networkcard"]."\",".
"software= \"".$formVars["software"]."\",".
"software2= \"".$formVars["software2"]."\",".
"software3= \"".$formVars["software3"]."\",".
"software4= \"".$formVars["software4"]."\",".
"software5= \"".$formVars["software5"]."\",".
"software6= \"".$formVars["software6"]."\",".
"software7= \"".$formVars["software7"]."\",".
"software8= \"".$formVars["software8"]."\",".
"software9= \"".$formVars["software9"]."\",".
"software10= \"".$formVars["software10"]."\",".
"license= \"".$formVars["license"]."\",".
"license2= \"".$formVars["license2"]."\",".
"license3= \"".$formVars["license3"]."\",".
"license4= \"".$formVars["license4"]."\",".
"license5= \"".$formVars["license5"]."\",".
"license6= \"".$formVars["license6"]."\",".
"license7= \"".$formVars["license7"]."\",".
"license8= \"".$formVars["license8"]."\",".
"license9= \"".$formVars["license9"]."\",".
"license10= \"".$formVars["license10"]."\",".
"location= \"".$formVars["location"]."\",".
"motherboard= \"".$formVars["motherboard"]."\" WHERE asset = \"".$formVars["asset"]."\"";
mysql_query($query);
mysql_close($db);
?>

and here is line 26 from the above code;

query="UPDATE dedicated set ".


Please help!!!

Posted: Wed Jan 26, 2005 7:07 am
by Wayne
$query = ...

you might also want to look at the way you write your statement, it works, buts its not the neatest way of doing it.

Posted: Wed Jan 26, 2005 7:14 am
by mhouldridge
Thank you, that's sorted it.

You mentioned about the way I have put this together. Would there be an easier way. Please could you suggest something?

thanks again.

Posted: Wed Jan 26, 2005 7:39 am
by Wayne
there are a couple of ways you could do it, the way you have is one of them, but not that tidy to read afterwards, have a look at sprintf() for a start.

Posted: Wed Jan 26, 2005 7:43 am
by timvw
as the column names appear to be the same as the keys in formvars...

Code: Select all

$ignore = array ('asset');

$query = "UPDATE whatever SET ";
foreach($formvars as $key => $val)
&#123;
       if (!in_array($key, $ignore)
       &#123;
           $val = mysql_escape_string($val);
           $query .= "$key='$val', ";
        &#125;
&#125;
// chop off last , 
$query = rtrim($query, ", ");
$asset = mysql_escape_string($formvars&#1111;'asset'];
$query .= "WHERE asset='$asset'";