Talha Farooq Talha Farooq - 1 year ago 181
HTML Question

MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near

I am facing this error in my code I have my PHP code is like..

$num = $_POST['h'];


if(isset($_REQUEST["quantity$i"])){$quantity = $_REQUEST["quantity$i"];}
if(isset($_REQUEST["purchase$i"])){$purchase = $_REQUEST["purchase$i"];}else{$purchase= 'purchase';} //for error controling
if(isset($_REQUEST["sale$i"])){$sale = $_REQUEST["sale$i"];}else{$sale = 00;} //for error controling
$sql="INSERT into myaccounts

('quantity','purchase','sale') values ('$quantity','$purchase','$sale')"; //for error controling
if(mysqli_query($dbh, $sql))
echo "Sucess";

} else {
echo 'MySQL Error: ' . mysqli_error($dbh);

The element
is in
code is

<table class="table table-bordered table-hover" id="tab_logic">
<tr >
<th class="text-center">
<th class="text-center">
<th class="text-center">
Purchase Price
<th class="text-center">
Sale Price
<th class="text-center">
Profit Or Loss


<tr id='addr0'></tr>

<button type="submit" value="Register" name="submit" class="btn btn-default pull-">Submit</button>

<input type="hidden" name="h" id="h" />

<a id="add_row" class="btn btn-default pull-left">Add Row</a><a id='delete_row' class="pull-right btn btn-default">Delete Row</a>

var i=0;
$('#addr'+i).html("<td>"+ (i+1) +"</td><td><input name='quantity"+i+"' type='text' placeholder='Name' class='form-control input-md' /></td><td><input name='purchase"+i+"' type='text' placeholder='Purchase' class='form-control input-md'></td><td><input name='sale"+i+"' type='text' placeholder='Sale ' class='form-control input-md'></td>");

$('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');


I have build up signup and login form using same
query now I am unable to achieve result here.

Answer Source

Remove single quotes from field names, like bellow:

$sql="INSERT INTO myaccounts (quantity,purchase,sale) values ('$quantity','$purchase','$sale')"; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download