garevn Posted May 23, 2011 Share Posted May 23, 2011 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 More sharing options...
2old2learn? Posted May 23, 2011 Share Posted May 23, 2011 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 More sharing options...
justsomeguy Posted May 23, 2011 Share Posted May 23, 2011 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 More sharing options...
thescientist Posted May 23, 2011 Share Posted May 23, 2011 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 More sharing options...
garevn Posted May 23, 2011 Author Share Posted May 23, 2011 tnx bro i didnt really need all that stuff and i made is $cartTotal="$".$cartTotal."";It works great now Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.