colleyboy Posted September 19, 2010 Share Posted September 19, 2010 I am getting this error when updating a record (through a form) Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/updates.php on line 62 This is updates.php <?php mysql_connect("localhost", "wormste1_barry", "barry") or die(mysql_error()); mysql_select_db("wormste1_barry") or die(mysql_error()); $carname = mysql_real_escape_string(trim($_POST['CarName'])); $cartitle = mysql_real_escape_string(trim($_POST['CarTitle'])); $carprice = mysql_real_escape_string(trim($_POST['CarPrice'])); $carmiles = mysql_real_escape_string(trim($_POST['CarMiles'])); $cardesc = mysql_real_escape_string(trim($_POST['CarDescription'])); mysql_query("UPDATE cars WHERE id='.intval ($_GET['id']).' LIMIT 1 (CarName, CarTitle, CarPrice, CarMiles, CarDescription, photo) VALUES('$carname', '$cartitle', '$carprice', '$carmiles', '$cardesc' ) ") or die(mysql_error()); echo "The vehicle data has been updated!"; ?> the updates.php actually processes the update. the form page is edit.php: <CENTER><B>Update a Vehicle</B></CENTER> <BR> <?php $what_id=$_GET['id']; $query="SELECT * FROM cars WHERE id = '$what_id'"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { $carname = $row['CarName']; $cartitle = $row['CarTitle']; $carprice = $row['CarPrice']; $carmiles = $row['CarMiles']; $cardesc = $row['CarDescription']; } ?> <form action="updates.php" method="post"> <CENTER>Vehicle Name:</CENTER> <br><CENTER><input type="text" name="CarName" value="<?php echo $carname; ?>"></CENTER><br> <CENTER>Vehicle Type:</CENTER><br><CENTER><input type="text" name="CarTitle" value="<?php echo $cartitle; ?>"></CENTER><br> <CENTER>Vehicle Price:</CENTER><br><CENTER><input type="text" name="CarPrice" value="<?php echo $carprice; ?>"></CENTER><br> <CENTER>Vehicle Mileage:</CENTER><br><CENTER><input type="text" name="CarMiles" value="<?php echo $carmiles; ?>"></CENTER><br> <CENTER>Vehicle Description:</CENTER><br><CENTER><input type="text" name="CarDescription" value="<?php echo $cardesc; ?>"></CENTER><br> <CENTER>Vehicle Description:</CENTER><br> <CENTER><textarea name="CarDescription" rows="10" cols="30" value="<?php echo nl2br($cardesc); ?>"></textarea></CENTER><br> <CENTER><input type="Submit"></CENTER> </form> Any idea for the error. I think it could be because the UPDATE tag syntax is wrong. Help would be great!!! Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 19, 2010 Share Posted September 19, 2010 Yes, the syntax is wrong. UPDATE `table` SET `field_1` = 'value_1', `field_2` = 'value_2' WHERE `some_field` = 'some_value' LIMIT 1 UPDATE query syntax Quote Link to comment Share on other sites More sharing options...
colleyboy Posted September 19, 2010 Author Share Posted September 19, 2010 so what do I actually write in this case pikachu? Sorry... bit of a newbie Quote Link to comment Share on other sites More sharing options...
litebearer Posted September 19, 2010 Share Posted September 19, 2010 add this to your form <input type="hidden" name="what_id" value="<?PHP echo $what_id; ?>"> then change this... mysql_query("UPDATE cars WHERE id='.intval ($_GET['id']).' LIMIT 1 (CarName, CarTitle, CarPrice, CarMiles, CarDescription, photo) VALUES('$carname', '$cartitle', '$carprice', '$carmiles', '$cardesc' ) ") or die(mysql_error()); to this... $what_id=$_POST['what_id']; mysql_query("UPDATE cars CarName='$carname', CarTitle='$cartitle', CarPrice='$carprice', CarMiles='$carmiles', CarDescription='$cardesc' WHERE id = '$what_id'") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
colleyboy Posted September 19, 2010 Author Share Posted September 19, 2010 litebearer... have mde the changed but still get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='Ford Cortina', CarTitle='Saloon', CarPrice='£1250', CarMiles='99999', CarDescr' at line 1 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 19, 2010 Share Posted September 19, 2010 Missing SET. Quote Link to comment Share on other sites More sharing options...
litebearer Posted September 19, 2010 Share Posted September 19, 2010 Oops, thanks Pika Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.