Jump to content

php POST problem


WatsonN

Recommended Posts

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

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.