WatsonN Posted October 9, 2010 Share Posted October 9, 2010 I have a form that is supposed to update a mysql row. The problem is that it wont post the $id to the script here is the form: form method="post" action=""> <label class="description" for="element_1">Payment Status: </label> <select class="element select medium" id="element_1" name="element_1"> <option value="Paid" SELECTED>Paid</option> <option value="Bill Sent" >Bill Sent</option> <option value="Check to be cashed" >Check to be cashed</option> </select> <input type="hidden" name="id" vlaue="<?php Print $ID; ?>"> <input id="saveForm" class="button_text" type="submit" name="payment" value="Update" /> </li> </ul><br><?php Print "Payment Status: <b>".$info['payment'] . "</b>"; ?> </form> here is the php side: if (isset($_POST['payment'])) { mysql_real_escape_string($insert = "INSERT INTO `YBK_Ads` (`payment`) VALUES ('{$_POST['element_1']}') WHERE `YBK_Ads`.`ID` = '".$_POST['id']."'"); mysql_query($insert) or die( 'Query string: ' . $insert . '<br />Produced an error: ' . mysql_error() . '<br />' ); $error="<span style="; $error .="color:green"; $error .=">"; $error .= "<p>Thank you, the Payment status has been updated.</p>"; $error .="</span>"; setcookie('Errors', $error, time()+20); header('Location: /list.php'); exit; die; } ?> I'm getting this on post Query string: INSERT INTO `YBK_Ads` (`payment`) VALUES ('Paid') WHERE `YBK_Ads`.`ID` = '' Produced an 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 'WHERE `YBK_Ads`.`ID` = ''' at line 1 its not putting anything in the ID value Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/ Share on other sites More sharing options...
Pikachu2000 Posted October 9, 2010 Share Posted October 9, 2010 Are you trying to insert a new record, or update an existing record? Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120453 Share on other sites More sharing options...
WatsonN Posted October 9, 2010 Author Share Posted October 9, 2010 Update existing . . . I probally need to use UPDATE dont i -edit- spelling -edit- Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120454 Share on other sites More sharing options...
WatsonN Posted October 9, 2010 Author Share Posted October 9, 2010 Changed to ($insert = "UPDATE `YBK_Ads` (`payment`) VALUES ('{$_POST['element_1']}') WHERE `YBK_Ads`.`ID` = '".$_POST['id']."'") Error: Query string: UPDATE `YBK_Ads` (`payment`) VALUES ('Paid') WHERE `YBK_Ads`.`ID` = '' Produced an 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 '(`payment`) VALUES ('Paid') WHERE `YBK_Ads`.`ID` = ''' at line 1 Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120458 Share on other sites More sharing options...
Pikachu2000 Posted October 9, 2010 Share Posted October 9, 2010 The query syntax is wrong. Update syntax is UPDATE `table` SET `field1` = 'value1', `field2` = 'value2' WHERE `field` = 'value' Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120462 Share on other sites More sharing options...
WatsonN Posted October 9, 2010 Author Share Posted October 9, 2010 Changed to UPDATE `YBK_` SET `payment` = '$_POST[\'element_1\']' WHERE `ID` = '$_POST['id']' And I get Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/n/a/t/nathanwatson/html/admin/YBK/list.php on line 7 Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120466 Share on other sites More sharing options...
Pikachu2000 Posted October 9, 2010 Share Posted October 9, 2010 You should just need to enclose the $_POST array elements in curly braces, or use string concatenation. I find the curlies easier to read . . . UPDATE `YBK_` SET `payment` = '{$_POST['element_1']}' WHERE `ID` = '{$_POST['id']}' Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120469 Share on other sites More sharing options...
WatsonN Posted October 9, 2010 Author Share Posted October 9, 2010 Works perfectly Thanks Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120623 Share on other sites More sharing options...
WatsonN Posted October 9, 2010 Author Share Posted October 9, 2010 Spoke too soon Query string: INSERT INTO `YBK_Ads` (`payment`) VALUES ('Bill Sent') WHERE `YBK_Ads`.`ID` = '' Produced an 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 'WHERE `YBK_Ads`.`ID` = ''' at line 1 code if (isset($_POST['payment'])) { mysql_real_escape_string($insert = "INSERT INTO `YBK_Ads` (`payment`) VALUES ('{$_POST['element_1']}') WHERE `YBK_Ads`.`ID` = '".$_POST['id']."'"); mysql_query($insert) or die( 'Query string: ' . $insert . '<br />Produced an error: ' . mysql_error() . '<br />' ); $error="<span style="; $error .="color:green"; $error .=">"; $error .= "<p>Thank you, the Payment status has been updated.</p>"; $error .="</span>"; setcookie('Errors', $error, time()+20); header('Location: /list.php'); exit; die; Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120629 Share on other sites More sharing options...
Pikachu2000 Posted October 9, 2010 Share Posted October 9, 2010 I thought you said you wanted to UPDATE the table? Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120631 Share on other sites More sharing options...
WatsonN Posted October 9, 2010 Author Share Posted October 9, 2010 I'm sorry today hasnt been my day if (isset($_POST['payment'])) { mysql_real_escape_string($insert = "UPDATE `YBK_Ads` SET `payment` = '{$_POST['element_1']}' WHERE `ID` = '{$_POST['id']}'"); mysql_query($insert) or die( 'Query string: ' . $insert . '<br />Produced an error: ' . mysql_error() . '<br />' ); $error="<span style="; $error .="color:green"; $error .=">"; $error .= "<p>Thank you, the Payment status has been updated.</p>"; $error .="</span>"; setcookie('Errors', $error, time()+20); //header('Location: /?p=YearbookM'); exit; die; } Its not producing any error but its not updating either Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120633 Share on other sites More sharing options...
BlueSkyIS Posted October 9, 2010 Share Posted October 9, 2010 is this valid syntax?? mysql_real_escape_string($insert = "UPDATE `YBK_Ads` SET `payment` = '{$_POST['element_1']}' WHERE `ID` = '{$_POST['id']}'"); I would expect something more like $insert = "UPDATE `YBK_Ads` SET `payment` = '".mysql_real_escape_string($_POST['element_1'])."' WHERE `ID` = '".mysql_real_escape_string($_POST['id'])."'" Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120634 Share on other sites More sharing options...
WatsonN Posted October 9, 2010 Author Share Posted October 9, 2010 I changed it to that and echoed it and I still can't get it to echo the ID Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120640 Share on other sites More sharing options...
BlueSkyIS Posted October 9, 2010 Share Posted October 9, 2010 on the form, before you post, view source and see if the hidden field id is set. <input type="hidden" name="id" vlaue="<?php Print $ID; ?>"> Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120662 Share on other sites More sharing options...
WatsonN Posted October 10, 2010 Author Share Posted October 10, 2010 It wasn't posting I fixed it and works perfectly. Thank yall so much for the hep Link to comment https://forums.phpfreaks.com/topic/215473-php-post-problem/#findComment-1120712 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.