2

I am updating the data in database from php and Getting Up Error:Query was empty with query. I badly need help. Thanks in Advance

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$myDBname = 'jsv';
$conn = mysql_connect("localhost", "root");
mysql_select_db('jsv');
if(isset($_POST['update']))
{
$nam = $_POST['namnid'];
$mandag = $_POST['mandagid'];
$tisdag = $_POST['tisdagid'];
$torsdag = $_POST['torsdagid'];
$fredag = $_POST['fredagid'];

$sql = mysql_query("INSERT INTO jsv(CA_ID,Name,Address,Amount)  VALUES ('$mandag', '$tisdag', '$torsdag', '$fredag') WHERE Setup_Box_No = '$nam'", $conn);
if(!$sql )
{
  die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";

}

mysql_close($conn);
?>
yunzen
  • 32,854
  • 11
  • 73
  • 106

1 Answers1

1

MySQL does not support a WHERE clause in an INSERT statement. This causes your query to fail & makes $sql false.

You will need to rewrite your INSERT statement.

This answer should give you more explanation on alternative queries.

ItsPete
  • 2,363
  • 3
  • 27
  • 35
  • Please don't link to an answer, instead vote to close as duplicate – mplungjan Apr 08 '19 at 06:56
  • Thanks .. It Worked... But Now I am getting Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax. Pls Help me.. – Ashok Kumar Apr 08 '19 at 17:19
  • @AshokKumar, I'd need to see your query, but the query in your question is trying to insert "$mandag" as a string rather than the value of `$mandag`. You need to concatenate them, eg. `... VALUES ('".$mandag."', ...` – ItsPete Apr 08 '19 at 23:15