SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    760
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    Code:
    $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());

  2. #2
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,255
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Hi,

    What you need is an UPDATE query, which is like this:
    Code MySQL:
    UPDATE myTable
    SET column1 = value1, column2 = value2
    WHERE column3 = value3

  3. #3
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    760
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi fretburner again,

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

    Thanks again

  4. #4
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    760
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    Code:
    $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());

  5. #5
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,255
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Looking like you're missing quotes around your values.

    Edit: snap!

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,042
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    The strings need to be wrapped in single quotes.
    The only code I hate more than my own is everyone else's.

  7. #7
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    760
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bingo, thank you guys...

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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •