php mysql WHERE clause Syntax error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vivekneo
    New Member
    • Sep 2010
    • 18

    php mysql WHERE clause Syntax error

    Hi, iam trying to insert values in the child table, with condition that both pk and fk should match,
    pk = stud_id and fk dstud_id.
    here is what iam trying
    Code:
    include('config.php'); 
    if (isset($_GET['stud_id']) ) { 
    $id = (int) $_GET['stud_id']; 
    if (isset($_POST['submitted'])) { 
    
    foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } 
    
    $sql = "INSERT INTO `cjet`.`student_don_reg_history` (`stud_full_name`,`course_place`,`course_year`,
    `course_name`,`stud_reg_no`,`don_amt`,`dd_no`) 
    VALUES('{$_POST['stud_full_name']}','{$_POST['place']}',
    '{$_POST['year']}','{$_POST['course']}','{$_POST['stud_reg']}',
    '{$_POST['don_amt']}','{$_POST['dd_no']}')WHERE `dstud_id` = '$id' ";
    
    mysql_query($sql) or die(mysql_error());
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    INSERTs do not have a WHERE clause.

    Comment

    • kovik
      Recognized Expert Top Contributor
      • Jun 2007
      • 1044

      #3
      If the ID is already known but you aren't sure if the record exists, you may wish to use REPLACE INTO instead of INSERT INTO.

      Comment

      • Max Burke

        #4
        Many Thanks Markus, your comment just ended an hour of mepulling my hair out! :)

        Comment

        Working...