toothpick007 Posted March 21, 2012 Share Posted March 21, 2012 mysql_query("UPDATE BTECL31113 SET FirstName='$ud_FirstName' , LastName='$ud_LastName' , GroupCode='$ud_GroupCode' , Unit1='$ud_P_Unit1' , Unit2='$ud_P_Unit2' , Unit3='$ud_P_Unit3' , Unit6='$ud_P_Unit6' , Unit14='$ud_P_Unit14' , Unit20='$ud_P_Unit20' , Unit27='$ud_P_Unit27' , Unit28='$ud_P_Unit28' , Unit42='$ud_P_Unit42' , Unit10='$ud_P_Unit10' , Unit11='$ud_P_Unit11' , Unit12='$ud_P_Unit12' , Unit13='$ud_P_Unit13' , Unit1454='$ud_P_Unit1454' , Unit15='$ud_P_Unit15' , Unit16= $ud_P_Unit16' , Unit17='$ud_P_Unit17' , Unit18='$ud_P_Unit18' WHERE P_Id='$ud_P_Id'"); Because for some reason its not writting to my database !!!!! Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/ Share on other sites More sharing options...
trq Posted March 21, 2012 Share Posted March 21, 2012 What error are you getting? Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/#findComment-1329787 Share on other sites More sharing options...
toothpick007 Posted March 21, 2012 Author Share Posted March 21, 2012 Im not getting a error at all its just not writting to the database for some strange reason .... Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/#findComment-1329790 Share on other sites More sharing options...
trq Posted March 21, 2012 Share Posted March 21, 2012 What have you done to debug the issue then? You can trap database error you know? See mysql_error. Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/#findComment-1329792 Share on other sites More sharing options...
toothpick007 Posted March 21, 2012 Author Share Posted March 21, 2012 Where would i put it in here ???? if (! $con) die("Couldn't connect to MySQL"); mysql_select_db($db , $con) or die("Couldn't open $db: ".mysql_error()); mysql_query("UPDATE BTECL31113 SET FirstName='$ud_FirstName' , LastName='$ud_LastName' , GroupCode='$ud_GroupCode' , Unit1='$ud_P_Unit1' , Unit2='$ud_P_Unit2' , Unit3='$ud_P_Unit3' , Unit6='$ud_P_Unit6' , Unit14='$ud_P_Unit14' , Unit20='$ud_P_Unit20' , Unit27='$ud_P_Unit27' , Unit28='$ud_P_Unit28' , Unit42='$ud_P_Unit42' , Unit10='$ud_P_Unit10' , Unit11='$ud_P_Unit11' , Unit12='$ud_P_Unit12' , Unit13='$ud_P_Unit13' , Unit1454='$ud_P_Unit1454' , Unit15='$ud_P_Unit15' , Unit16= $ud_P_Unit16' , Unit17='$ud_P_Unit17' , Unit18='$ud_P_Unit18' WHERE P_Id='$ud_P_Id'"); echo "Record Updated"; mysql_close($con); Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/#findComment-1329795 Share on other sites More sharing options...
trq Posted March 21, 2012 Share Posted March 21, 2012 mysql_query returns a bool, so check that. if (!mysql_query("UPDATE BTECL31113 SET FirstName='$ud_FirstName' , LastName='$ud_LastName' , GroupCode='$ud_GroupCode' , Unit1='$ud_P_Unit1' , Unit2='$ud_P_Unit2' , Unit3='$ud_P_Unit3' , Unit6='$ud_P_Unit6' , Unit14='$ud_P_Unit14' , Unit20='$ud_P_Unit20' , Unit27='$ud_P_Unit27' , Unit28='$ud_P_Unit28' , Unit42='$ud_P_Unit42' , Unit10='$ud_P_Unit10' , Unit11='$ud_P_Unit11' , Unit12='$ud_P_Unit12' , Unit13='$ud_P_Unit13' , Unit1454='$ud_P_Unit1454' , Unit15='$ud_P_Unit15' , Unit16= $ud_P_Unit16' , Unit17='$ud_P_Unit17' , Unit18='$ud_P_Unit18' WHERE P_Id='$ud_P_Id'")) { echo mysql_error(); } ps: Your database design is completely floored. Any time you see fields such as foo1, foo2, foo3, foo4 etc etc screams database normalisation is required. Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/#findComment-1329797 Share on other sites More sharing options...
toothpick007 Posted March 21, 2012 Author Share Posted March 21, 2012 Yea im going to fix it all just getting the basic stuff out the way first .... I now have a error this is what gets returned .... 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 '178723'' at line 1Record Updated 178723Bouachanh; Sony; A; D; M; ; ; P; M; ; D; M; ; ; ; ; ; ; ; ; ; Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/#findComment-1329800 Share on other sites More sharing options...
trq Posted March 21, 2012 Share Posted March 21, 2012 Are you escaping any of your data before using it? Take a look at mysql_real_escape_string. Looks like some of your data might have quotes in it. Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/#findComment-1329801 Share on other sites More sharing options...
toothpick007 Posted March 21, 2012 Author Share Posted March 21, 2012 I am yes here is all the code on that page but I cant seem to find any quotes :-? <? $ud_P_Id = $_POST['ud_P_Id']; $ud_LastName = $_POST['ud_LastName']; $ud_FirstName = $_POST['ud_FirstName']; $ud_GroupCode=$_POST['ud_GroupCode']; $ud_P_Unit1=$_POST['ud_P_Unit1']; $ud_P_Unit2=$_POST['ud_P_Unit2']; $ud_P_Unit3=$_POST['ud_P_Unit3']; $ud_P_Unit6=$_POST['ud_P_Unit6']; $ud_P_Unit14=$_POST['ud_P_Unit14']; $ud_P_Unit20=$_POST['ud_P_Unit20']; $ud_P_Unit27=$_POST['ud_P_Unit27']; $ud_P_Unit28=$_POST['ud_P_Unit28']; $ud_P_Unit42=$_POST['ud_P_Unit42']; $ud_P_Unit10=$_POST['ud_P_Unit10']; $ud_P_Unit11=$_POST['ud_P_Unit11']; $ud_P_Unit12=$_POST['ud_P_Unit12']; $ud_P_Unit13=$_POST['ud_P_Unit13']; $ud_P_Unit1454=$_POST['ud_P_Unit1454']; $ud_P_Unit15=$_POST['ud_P_Unit15']; $ud_P_Unit16=$_POST['ud_P_Unit16']; $ud_P_Unit17=$_POST['ud_P_Unit17']; $ud_P_Unit18=$_POST['ud_P_Unit18']; $con = mysql_connect('localhost', 'lccstude_progre', '********'); $db= "lccstude_pro"; if (! $con) die("Couldn't connect to MySQL"); mysql_select_db($db , $con) or die("Couldn't open $db: ".mysql_error()); if (!mysql_query("UPDATE BTECL31113 SET FirstName='$ud_FirstName' , LastName='$ud_LastName' , GroupCode='$ud_GroupCode' , Unit1='$ud_P_Unit1' , Unit2='$ud_P_Unit2' , Unit3='$ud_P_Unit3' , Unit6='$ud_P_Unit6' , Unit14='$ud_P_Unit14' , Unit20='$ud_P_Unit20' , Unit27='$ud_P_Unit27' , Unit28='$ud_P_Unit28' , Unit42='$ud_P_Unit42' , Unit10='$ud_P_Unit10' , Unit11='$ud_P_Unit11' , Unit12='$ud_P_Unit12' , Unit13='$ud_P_Unit13' , Unit1454='$ud_P_Unit1454' , Unit15='$ud_P_Unit15' , Unit16= $ud_P_Unit16' , Unit17='$ud_P_Unit17' , Unit18='$ud_P_Unit18' WHERE P_Id='$ud_P_Id' ")) { echo mysql_error(); }; echo "Record Updated"; mysql_close($con); ?> <? echo $ud_P_Id ?> <? echo $ud_LastName ?>; <? echo $ud_FirstName ?>; <? echo $ud_GroupCode?>; <? echo $ud_P_Unit1 ?>; <? echo $ud_P_Unit2 ?>; <? echo $ud_P_Unit3 ?>; <? echo $ud_P_Unit6 ?>; <? echo $ud_P_Unit14 ?>; <? echo $ud_P_Unit20 ?>; <? echo $ud_P_Unit27 ?>; <? echo $ud_P_Unit28 ?>; <? echo $ud_P_Unit42 ?>; <? echo $ud_P_Unit10 ?>; <? echo $ud_P_Unit11 ?>; <? echo $ud_P_Unit12 ?>; <? echo $ud_P_Unit13 ?>; <? echo $ud_P_Unit1454 ?>; <? echo $ud_P_Unit15 ?>; <? echo $ud_P_Unit16 ?>; <? echo $ud_P_Unit17 ?>; <? echo $ud_P_Unit18 ?>; Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/#findComment-1329803 Share on other sites More sharing options...
trq Posted March 21, 2012 Share Posted March 21, 2012 That code does nothing to escape any special chars. Again, see mysql_real_escape_string. Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/#findComment-1329807 Share on other sites More sharing options...
toothpick007 Posted March 21, 2012 Author Share Posted March 21, 2012 ok ive done it i sent the wrong code oops ... <? $con = mysql_connect('localhost', 'lccstude_progre', '*******'); $db= "lccstude_pro"; if (! $con) die("Couldn't connect to MySQL"); mysql_select_db($db , $con) or die("Couldn't open $db: ".mysql_error()); $ud_P_Id = mysql_real_escape_string( $_POST['ud_P_Id']); $ud_LastName = mysql_real_escape_string( $_POST['ud_LastName']); $ud_FirstName = mysql_real_escape_string( $_POST['ud_FirstName']); $ud_GroupCode = mysql_real_escape_string($_POST['ud_GroupCode']); $ud_P_Unit1 = mysql_real_escape_string($_POST['ud_P_Unit1']); $ud_P_Unit2 = mysql_real_escape_string($_POST['ud_P_Unit2']); $ud_P_Unit3 = mysql_real_escape_string($_POST['ud_P_Unit3']); $ud_P_Unit6 = mysql_real_escape_string($_POST['ud_P_Unit6']); $ud_P_Unit14 = mysql_real_escape_string($_POST['ud_P_Unit14']); $ud_P_Unit20 = mysql_real_escape_string($_POST['ud_P_Unit20']); $ud_P_Unit27 = mysql_real_escape_string($_POST['ud_P_Unit27']); $ud_P_Unit28 = mysql_real_escape_string($_POST['ud_P_Unit28']); $ud_P_Unit42 = mysql_real_escape_string($_POST['ud_P_Unit42']); $ud_P_Unit10 = mysql_real_escape_string($_POST['ud_P_Unit10']); $ud_P_Unit11 = mysql_real_escape_string($_POST['ud_P_Unit11']); $ud_P_Unit12 = mysql_real_escape_string($_POST['ud_P_Unit12']); $ud_P_Unit13 = mysql_real_escape_string($_POST['ud_P_Unit13']); $ud_P_Unit1454 = mysql_real_escape_string($_POST['ud_P_Unit1454']); $ud_P_Unit15 = mysql_real_escape_string($_POST['ud_P_Unit15']); $ud_P_Unit16 = mysql_real_escape_string($_POST['ud_P_Unit16']); $ud_P_Unit17 = mysql_real_escape_string($_POST['ud_P_Unit17']); $ud_P_Unit18 = mysql_real_escape_string($_POST['ud_P_Unit18']); if (!mysql_query("UPDATE BTECL31113 SET FirstName='$ud_FirstName' , LastName='$ud_LastName' , GroupCode='$ud_GroupCode' , Unit1='$ud_P_Unit1' , Unit2='$ud_P_Unit2' , Unit3='$ud_P_Unit3' , Unit6='$ud_P_Unit6' , Unit14='$ud_P_Unit14' , Unit20='$ud_P_Unit20' , Unit27='$ud_P_Unit27' , Unit28='$ud_P_Unit28' , Unit42='$ud_P_Unit42' , Unit10='$ud_P_Unit10' , Unit11='$ud_P_Unit11' , Unit12='$ud_P_Unit12' , Unit13='$ud_P_Unit13' , Unit1454='$ud_P_Unit1454' , Unit15='$ud_P_Unit15' , Unit16= $ud_P_Unit16' , Unit17='$ud_P_Unit17' , Unit18='$ud_P_Unit18' WHERE P_Id='$ud_P_Id' ")) { echo mysql_error(); }; echo "Record Updated"; mysql_close($con); ?> However im still getting the same 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 '178723'' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/#findComment-1329808 Share on other sites More sharing options...
trq Posted March 21, 2012 Share Posted March 21, 2012 OK, one very good debugging trick is to echo your query. Change your code so you can see whats going on: $sql = "UPDATE BTECL31113 SET FirstName='$ud_FirstName' , LastName='$ud_LastName' , GroupCode='$ud_GroupCode' , Unit1='$ud_P_Unit1' , Unit2='$ud_P_Unit2' , Unit3='$ud_P_Unit3' , Unit6='$ud_P_Unit6' , Unit14='$ud_P_Unit14' , Unit20='$ud_P_Unit20' , Unit27='$ud_P_Unit27' , Unit28='$ud_P_Unit28' , Unit42='$ud_P_Unit42' , Unit10='$ud_P_Unit10' , Unit11='$ud_P_Unit11' , Unit12='$ud_P_Unit12' , Unit13='$ud_P_Unit13' , Unit1454='$ud_P_Unit1454' , Unit15='$ud_P_Unit15' , Unit16= $ud_P_Unit16' , Unit17='$ud_P_Unit17' , Unit18='$ud_P_Unit18' WHERE P_Id='$ud_P_Id'"; if (!mysql_query($sql)) { echo mysql_error() . "<br />" . $sql; }; What do you get now? Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/#findComment-1329818 Share on other sites More sharing options...
toothpick007 Posted March 21, 2012 Author Share Posted March 21, 2012 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 '178723'' at line 1 UPDATE BTECL31113 SET FirstName='Sony' , LastName='Bouachanh' , GroupCode='A' , Unit1='D' , Unit2='M' , Unit3=' ' , Unit6=' ' , Unit14='P' , Unit20='M' , Unit27=' ' , Unit28='D' , Unit42='M' , Unit10=' ' , Unit11=' ' , Unit12=' ' , Unit13=' ' , Unit1454=' ' , Unit15=' ' , Unit16= ' , Unit17=' ' , Unit18=' ' WHERE P_Id='178723' OMG its ok I found it I was missing a ' on unit 16 thank you so much you have been a great help and thank you so much for your time and your tips .... Quote Link to comment https://forums.phpfreaks.com/topic/259409-is-this-statment-wrong/#findComment-1329820 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.