-4
sql="insert into gd_stock(Stock_Purchase) values("$a['Quantity']") where Product_Model="$a['Model_No']"";

Here is shows the error :Parse error: syntax error, unexpected '='!

Mihir
  • 83
  • 2
  • 13

7 Answers7

3

Insert statements doesn't use a where clause except you want to insert into from another table conditionally which will first of all select from the table before inserting if not so your sql should be like this

  sql="insert into gd_stock(Stock_Purchase) values('". 
          $a['Quantity']. "')";
Ghost Worker
  • 635
  • 5
  • 16
2
$sql="insert into gd_stock(Stock_Purchase) values("$a['Quantity']") where 
 Product_Model=".$a['Model_No'];
if (!mysqli_query($con, $sql))
{
    echo("Error description: " . mysqli_error($con));
}
Awais Mustafa
  • 171
  • 2
  • 9
0
sql="insert into gd_stock(Stock_Purchase) values('{$a['Quantity']}') where Product_Model='{$a['Model_No']}'";
  1. you have a syntax error while you link your query strings. the double quota ends the string
  2. suggest you use {} to warp your variables in string
Fu Xu
  • 736
  • 2
  • 6
  • 20
0

USE $ symbol to define $sql.

  $sql="insert into gd_stock(Stock_Purchase) values('{$a['Quantity']}') where 
 Product_Model='{$a['Model_No']}'";;
Mr. Bhosale
  • 2,763
  • 1
  • 16
  • 33
0

Try this

$sql="insert into gd_stock(Stock_Purchase) values(". $a['Quantity']. ") where Product_Model=".     $a['Model_No']. "";

You did not concatenate (join) the string with the variable

smartnet
  • 87
  • 4
0

$dbconn - for your Mysql Database Connection

$insertsql="insert into gd_stock(Stock_Purchase) values("$a['Quantity']") where Product_Model=".$a['Model_No'];
if (!mysql_query($dbconn, $insertsql))
{
    echo("Error Details: " . mysql_error($con));
}
Karthik
  • 5,121
  • 14
  • 43
  • 69
-1

You need to escape your inner quotation marks.

try this:

$sql="insert into gd_stock(Stock_Purchase) values("$a['Quantity']") where Product_Model=\""$a['Model_No']"\"";
aconnelly
  • 640
  • 1
  • 6
  • 12