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
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.