bhavin_85 Posted March 6, 2007 Share Posted March 6, 2007 hi guys im trying to write an update query that updates a few fields in a row on my sql database im gettin a parse error and i cant figure out why <?php session_start(); if ( empty($_SESSION['username'])){ header("location:default.php"); exit; } $id=$_SESSION['cust_id']; include('config.php') $sql="UPDATE customer SET first_name = ".$_POST['first_name']" WHERE cust_id = '$id'"; mysql_query($sql) or die ("Couldnt execute $sql: " . mysql_error()); ?> ive used post because there is a form on the previous page which the user enters their updated values into Link to comment https://forums.phpfreaks.com/topic/41431-update-query-question/ Share on other sites More sharing options...
iceman400 Posted March 6, 2007 Share Posted March 6, 2007 try adding (') around the post['first_name'] like this: $sql="UPDATE customer SET first_name = [color=yellow][b]'[/b][/color]".$_POST['first_name']"[color=yellow][b]'[/b][/color] WHERE cust_id = '$id'"; Link to comment https://forums.phpfreaks.com/topic/41431-update-query-question/#findComment-200706 Share on other sites More sharing options...
trq Posted March 6, 2007 Share Posted March 6, 2007 Your missing the closing ; on this line... include('config.php') Also note that include is NOT a function and does not require the braces. include 'config.php'; Link to comment https://forums.phpfreaks.com/topic/41431-update-query-question/#findComment-200708 Share on other sites More sharing options...
bhavin_85 Posted March 6, 2007 Author Share Posted March 6, 2007 $sql="UPDATE customer SET first_name = '".$_POST['first_name']"' WHERE cust_id = '$id'"; gave that a try but im still getting a parse error says unexpected " Link to comment https://forums.phpfreaks.com/topic/41431-update-query-question/#findComment-200710 Share on other sites More sharing options...
trq Posted March 6, 2007 Share Posted March 6, 2007 $sql = "UPDATE customer SET first_name = '".$_POST['first_name']."' WHERE cust_id = '$id'"; Link to comment https://forums.phpfreaks.com/topic/41431-update-query-question/#findComment-200713 Share on other sites More sharing options...
bhavin_85 Posted March 6, 2007 Author Share Posted March 6, 2007 cheers i realised i was missing the . after the post if i have a date field set in one of the fields and the user has to update it how would i do it? the date is currently set at yyyy/mm/dd if i want it to be entered as dd/mm/yyyy but converted before its stored in the database? would a drop down list work? Link to comment https://forums.phpfreaks.com/topic/41431-update-query-question/#findComment-200721 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.