rleahong Posted June 9, 2013 Share Posted June 9, 2013 PHP CODE NOT WORKING $LABELNAM = $_POST['LABELNAM']; $LABELCOD = $_POST['LABELCOD']; $SQLLABEL = " UPDATE LABEL " . " SET LABELNAM = $LABELNAM " . " WHERE LABELCOD = $LABELCOD "; RESULTS = mysql_query( $SQLLABEL, $CON ); Link to comment https://forums.phpfreaks.com/topic/278972-php-code-not-updating-mysql-database-table/ Share on other sites More sharing options...
davidannis Posted June 9, 2013 Share Posted June 9, 2013 On the last line the variable should be $results and the connection variable should be before the query variable. You should also sanitize the data before the query. Link to comment https://forums.phpfreaks.com/topic/278972-php-code-not-updating-mysql-database-table/#findComment-1435042 Share on other sites More sharing options...
Psycho Posted June 9, 2013 Share Posted June 9, 2013 Also, unless the values are integers, you need to enclose them in quotes for the query $LABELNAM = $_POST['LABELNAM']; $LABELCOD = $_POST['LABELCOD']; $query = "UPDATE LABE SET LABELNAM = '$LABELNAME' WHERE LABELCOD = '$LABELCOD' "; $result = mysql_query($SQLLABEL, $CON); if(!$result) { die("Query: $query<br>Error: " . mysql_error()); } . . . the connection variable should be before the query variable. No it shouldn't.You are thinking of mysqli_query() Link to comment https://forums.phpfreaks.com/topic/278972-php-code-not-updating-mysql-database-table/#findComment-1435043 Share on other sites More sharing options...
davidannis Posted June 10, 2013 Share Posted June 10, 2013 No it shouldn't.You are thinking of mysqli_query() Oops, my bad. I almost exclusively use mysqli. Should have advised the OP to switch to mysqli since mysql is deprecated. Link to comment https://forums.phpfreaks.com/topic/278972-php-code-not-updating-mysql-database-table/#findComment-1435055 Share on other sites More sharing options...
rleahong Posted August 5, 2013 Author Share Posted August 5, 2013 Also, unless the values are integers, you need to enclose them in quotes for the query $LABELNAM = $_POST['LABELNAM']; $LABELCOD = $_POST['LABELCOD']; $query = "UPDATE LABE SET LABELNAM = '$LABELNAME' WHERE LABELCOD = '$LABELCOD' "; $result = mysql_query($SQLLABEL, $CON); if(!$result) { die("Query: $query<br>Error: " . mysql_error()); } LABELCOD IS AN INTEGER No it shouldn't.You are thinking of mysqli_query() Link to comment https://forums.phpfreaks.com/topic/278972-php-code-not-updating-mysql-database-table/#findComment-1443540 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.