Jump to content

[SOLVED] PHP + MySQL Update


s.eardley

Recommended Posts

Should this work because I get this 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 '(ExistingUser, ExistingSoftwareDetails, ExistingSoftwareEdition, SoftwareRequire' at line 1".

 

$OrderID = $_POST['OrderID'];
echo $OrderID;
echo "<br/><br/>";

$db = mysql_connect("localhost", "root", "");
mysql_select_db("mysql",$db);

$sql = "UPDATE tblorders (";

foreach($_POST as $field=>$value)
{
$sql .= "".$field.", ";
}

$sql = substr_replace($sql,"",-2);

$sql .= ") VALUES (";

foreach($_POST as $field=>$value)
{
$sql.= "'".$value."', ";
}

$sql = substr_replace($sql,"",-2);

$sql .= ") WHERE OrderID='".mysql_real_escape_string( $OrderID )."'";

$result = mysql_query($sql,$db);

Link to comment
https://forums.phpfreaks.com/topic/148932-solved-php-mysql-update/
Share on other sites

UPDATE tblorders (ExistingUser, ExistingSoftwareDetails, ExistingSoftwareEdition) VALUES ('on', 'V1', 'Single user') WHERE OrderID='7'

 

I've shortened it a little just to make it easier to look at but this is the basic format of the sql statement which is output.

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.