Valid Query? (Insert into, values, select, where)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gerrybytes
    New Member
    • Apr 2008
    • 11

    Valid Query? (Insert into, values, select, where)

    Is the following a vaild query, or does any one have any suggestion on how to change it to get the correct info i'm looking for?

    [CODE=mysql]
    $Engineer = $_POST['Engineer'];
    $Ref_No = $_POST['Ref_No'];

    $query = "INSERT INTO engineer (Ref_No,Title,F orename,Surname ,Email,Branch,M essage,Severity ,Engineer)
    VALUES('$Engine er')
    SELECT Ref_No,Title,Fo rename,Surname, Email,Branch,Me ssage,Severity FROM new_fault
    WHERE ref_no='$Ref_No '";

    $result = mysqli_query($c xn,$query) or die ('error making query');
    [/CODE]

    The table im trying to put info in to is called engineer. I want to input the data from table New_Fault that contains the SELECT values (Ref_No etc) also i want to put in the engineer name from the POST method.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    A simple modification to a SELECT INTO statement should have done the trick.

    Comment

    • chaarmann
      Recognized Expert Contributor
      • Nov 2007
      • 785

      #3
      as far as I know you cannot use values() and select together.
      Just make the engineer value part of the select statement. that means:

      [PHP]
      $Engineer = $_POST['Engineer'];
      $Ref_No = $_POST['Ref_No'];

      $query = "INSERT INTO engineer (Ref_No, Title, Forename, Surname, Email, Branch, Message, Severity, Engineer)
      SELECT Ref_No, Title, Forename, Surname, Email, Branch, Message, Severity, '$Engineer' as Engineer FROM new_fault
      WHERE ref_no='$Ref_No '";

      $result = mysqli_query($c xn,$query) or die ('error making query');
      [/PHP]

      Comment

      Working...