PHP parse error, please help!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

PHP parse error, please help!!

Post 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!!!
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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.
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post 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.
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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'";
Post Reply