Jump to content

PHP error when attempting to insert data into a table


dazman

Recommended Posts

i am getting this error any ideas if you can help?

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/solace/customer-confirm.php on line 67

 

line 67 is  this one: $insertaddress = mysql_query("INSERT INTO address (Address_ID...

 

I think it may be my syntax. Where i am taking the variables out of the $_POST array.

//start insert transaction
$starttransaction = mysql_query("START TRANSACTION") or die (mysql_error($error));
//insert address into addresstable. 
$insertaddress = mysql_query("INSERT INTO address (Address_ID, Address_Line1, Address_Line2, Address_Line3, ZipPostalCode, City, State, Country) VALUES ('$ADIDendnumber', '$_POST['Address_Line1']', '$_POST['Address_Line2']','$_POST['Address_Line3']', '$_POST['ZipPostalCode']', '$_POST['City']', '$_POST['State']', '$_POST['Country']')")or die (mysql_error($error)));
//insert customer into customertable.
$insertcustomer = mysql_query("INSERT INTO customer (Cust_Name, Cust_Phone, Cust_Fax, Address_ID, Cust_Email, Cust_Website, Cust_Climit, Tax_Code, Cust_Group, Cust_PaymentTerms, Cust_BankAccountNo) VALUES ('$_POST['Cust_Name']','$_POST['Cust_Phone']','$_POST['Cust_Fax']','$ADIDendnumber','$_POST['Cust_Email']','$_POST['Cust_Website']','$_POST['Cust_Climit']','$_POST['Tax_Code']','$_POST['Cust_Group']','$_POST['Cust_PaymentTerms']','$_POST['Cust_BankAccountNo']')")or die 
//check for errors ($error)
if (mysql_error($error)));
{
$rollback = mysql_query("ROLLBACK");
echo $error;
}
$commit = mysql_query("COMMIT");
echo 'Customer Inserted';

 

Great news!

It all seems to be working except for this IF statement.

 

I am trying to validate my transaction to say if there was an error then rollback and output the error, currently my code runs and inserts the data and it seems to be all good.

 

I took a stab in the dark of putting a variable in the mysql_error() function, assuming that if there was an error returned from the mysql server it would be put into the $error variable. Is there a best practice way to do this? Surely lots of people have used transactions before?

 

//start insert transaction
$starttransaction = mysql_query("START TRANSACTION") or die (mysql_error($error));
//insert address into addresstable. 
$insertaddress = mysql_query("INSERT INTO address (Address_ID, Address_Line1, Address_Line2, Address_Line3, ZipPostalCode, City, State, Country) VALUES ('$ADIDendnumber', '{$_POST['Address_Line1']}', '{$_POST['Address_Line2']}','{$_POST['Address_Line3']}', '{$_POST['ZipPostalCode']}', '{$_POST['City']}', '{$_POST['State']}', '{$_POST['Country']}')")or die (mysql_error($error));
//insert customer into customertable.
$insertcustomer = mysql_query("INSERT INTO customer (Cust_Name, Cust_Phone, Cust_Fax, Address_ID, Cust_Email, Cust_Website, Cust_Climit, Tax_Code, Cust_Group, Cust_PaymentTerms, Cust_BankAccountNo) VALUES ('{$_POST['Cust_Name']}','{$_POST['Cust_Phone']}','{$_POST['Cust_Fax']}','$ADIDendnumber','{$_POST['Cust_Email']}','{$_POST['Cust_Website']}','{$_POST['Cust_Climit']}','{$_POST['Tax_Code']}','{$_POST['Cust_Group']}','{$_POST['Cust_PaymentTerms']}','{$_POST['Cust_BankAccountNo']}')")or die (mysql_error($error));
//check for errors ($error)
if (is_str($error));
{
$rollback = mysql_query("ROLLBACK");
echo $error;
}
$commit = mysql_query("COMMIT");
echo 'Customer Inserted';

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.