Jump to content

Insert session data into mysql


garevn

Recommended Posts

Into my cart i have a total value which i am trying to insert into a table.my cart reffering $cartTotal:

$cartTotal="";..$cartTotal=number_format($pricetotal+$cartTotal,2,".","");..$cartTotal="<div align='center'>Cart Total: $".$cartTotal."</div>";

I use a session in page one

$_SESSION['cartTotal'] = $cartTotal;

I my insert page i have this:

$cartTotal=$_SESSION['cartTotal'] ;..$sql="INSERT INTO sales(address,cartTotal) VALUES('$_POST[address]','$cartTotal' )";

and i get an errorError: 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 'center'>Cart Total: $300.00' )' at line 2

Link to comment
Share on other sites

Into my cart i have a total value which i am trying to insert into a table.my cart reffering $cartTotal:
$cartTotal="";..$cartTotal=number_format($pricetotal+$cartTotal,2,".","");..$cartTotal="<div align='center'>Cart Total: $".$cartTotal."</div>";

I use a session in page one

$_SESSION['cartTotal'] = $cartTotal;

I my insert page i have this:

$cartTotal=$_SESSION['cartTotal'] ;..$sql="INSERT INTO sales(address,cartTotal) VALUES('$_POST[address]','$cartTotal' )";

and i get an errorError: 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 'center'>Cart Total: $300.00' )' at line 2

I could be wrong..but maybe
$sql="INSERT INTO sales(address,$cartTotal)VALUES('$_POST[address]',' $_POST[$cartTotal]')";

I am just trying to learn myself..

Link to comment
Share on other sites

If this is $cartTotal: $cartTotal="<div align='center'>Cart Total: $".$cartTotal."</div>";Then you need to escape those single quotes around center. You should use mysql_real_escape_string on the value. So you'll save text like this to that field:<div align='center'>Cart Total: $300</div>

Link to comment
Share on other sites

well, from your code example line 2 is everything you've left out (..), and the line before it is valid.edit: weird, somehow I missed a bunch of your post

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...