Can you use WHERE when doing an INSERT

I have a second part of a form, where the details for the first part are already in the database, and now I need to add the managers comments.
So can you use a WHERE clause when using INSERT as below:


$sql = mysql_query("INSERT INTO hazzard (Name, Employerofperson, Contactphone, Location, DateOccured, ProductionZone, NearMissDetails, Anyimmediateactions) WHERE UniqueIdentifier=".$report_ID." VALUES ('".mysql_real_escape_string($_SESSION['name_A'])."','".mysql_real_escape_string($_SESSION['companies_A'])."','".mysql_real_escape_string($_SESSION['numbers_A'])."','".mysql_real_escape_string($location)."','$current_time','$ProductionZone','".mysql_real_escape_string($detail)."','".mysql_real_escape_string($feedback)."')") or die (mysql_error());

Hi,

What you need is an UPDATE query, which is like this:

UPDATE myTable
SET column1 = value1, column2 = value2
WHERE column3 = value3

Hi fretburner again,

Yes of course, I’m rushing and jumping around the code and not thinking straight.

Thanks again

Im getting ther error below, and cant see any problem, my syntax seems correct

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 ‘with electricity, Rottcause=Defective materials or equipment, Behaviours=Deliber’ at line 1


$report_ID = $_GET['ID'];
session_start();
$hazardornearmiss = mysql_real_escape_string($_POST["hazardornearmiss"]);
$primarycause= mysql_real_escape_string($_POST["primarycause"]);
$primarycause2 = mysql_real_escape_string($_POST["rottcause"]);
$rootcause = mysql_real_escape_string($_POST["rootcause"]);
$behaviours = mysql_real_escape_string($_POST["behaviours"]);
$potentialoutcome = mysql_real_escape_string($_POST["potentialoutcome"]);
$likelihood = mysql_real_escape_string($_POST["likelihood"]);
$comments = mysql_real_escape_string($_POST["comments"]);
$seen = "1";

$sql = mysql_query("UPDATE hazzard SET HazardorNearMiss=$hazardornearmiss, Primarycause=$primarycause, Rottcause=$rootcause, Behaviours=$behaviours, PotentialOutcome=$potentialoutcome, Likelihood=$likelihood, Comments=$comments, seenByManager=$seen WHERE UniqueIdentifier=$report_ID") or die (mysql_error());

The strings need to be wrapped in single quotes.

Looking like you’re missing quotes around your values.

Edit: snap!

Bingo, thank you guys…

Thats a good night from me now, take care all.