MySQL error at line 1 when I try to insert values -


php script:

<?php include('connect.php');  if (isset($_post['project_name'])){     $name = $_post['project_name'];     $date = $_post['date'];     $amount = $_post['amount'];     $curr = $_post['curr'];     $spec = $_post['spec'];     $sql = "insert projects (name, date, currency, amount, specifications) values '$name','$date','$amount','$curr','$spec'" or die(mysql_error()."update failed");     $insert = mysql_query($sql);         if($insert){ echo "successful"; echo "<br>"; echo "<a href='insert.php'>back main page</a>"; } else { ?> html form here <?php } ?> 

note: connect.php file working ok since i've used before on other scripts on same server.

every time try submit form (method = post), error: you have error in sql syntax; check manual corresponds mysql server version right syntax use near ''sad','08/13/2013','244','dollars','sdasd'' @ line 1 32767

what problem?

while inserting, values given row have enclosed in parenthesis.

insert projects (name, date, currency, amount, specifications) values       ('$name','$date','$amount','$curr','$spec') 

in order remember that, have remember insert allow add several rows, that's why each row has delimited parenthesis:

-- example, insert 3 time same row insert projects (name, date, currency, amount, specifications) values     ('$name','$date','$amount','$curr','$spec'),     ('$name','$date','$amount','$curr','$spec'),     ('$name','$date','$amount','$curr','$spec'); 

btw, please note using string interpolation build query major risk of sql injection. please see how can prevent sql injection in php? details.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -