SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    error in your SQL syntax

    This is actually in another thread but I'm sure no one is looking there at the moment. Does anyone know what might be causing this error? I've posted it here and included the whole php script but it is a mysql error so hopefully I'm put it in the correct place. Feel free to move it to the php section if needed.

    I'm using mysql version: 5.0.24-standard

    Error executing 1 due to 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 '1' at line 1
    PHP Code:
    <?php
    session_start
    (); 
    if(
    $_SESSION['login'] != 'Logged') { 
    header("Location: index.php"); 


    $sid $_SESSION['id'];
    $hpc $_SESSION['hpc_number'];



    // OPEN THE DATABASE CONNECTION
    $conn=mysql_connect ("localhost""user""password") or die ('I cannot connect to the database because: ' mysql_error());

    // PICK THE DATABASE TO USE
    mysql_select_db ("database",$conn); 

    // CREATE THE SQL STATEMENT

    $sql mysql_query("INSERT INTO paralog_response 
        (responseid,paramedicid,jobtypeid,ptgenderid,ptethnicid,ptage,prf,date) 
        values 
        (NULL,'
    $hpc','$_POST[job_type]','$_POST[sex]','$_POST[ethnic]','$_POST[age]','$_POST[prf]','$_POST[date]')"); 

    $responseid mysql_insert_id();

    foreach(
    $procedure as $element){
    $sql mysql_query("INSERT INTO paralog_responseprocedure 
        (responseid,procedureid) 
        values 
        ('
    $responseid', '$element')"); 
    }

    foreach(
    $drug as $element){
    $sql mysql_query("INSERT INTO paralog_responsedrug 
        (responseid,drugcode) 
        values 
        ('
    $responseid','$element')"); 





    // EXECUTE THE SQL STATEMENT


    if (mysql_query($sql,$conn)) {
          
    // redirect
              
    header('Location: enter_job_successfully.htm');
    } else {
    echo 
    'Error executing ' $sql ' due to ' mysql_error();
    }
    ?>

  2. #2
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The column that yu are trying to insert the null value in. what type is it?

  3. #3
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    remove this part of your code
    PHP Code:
    // EXECUTE THE SQL STATEMENT


    if (mysql_query($sql,$conn)) {
          
    // redirect
              
    header('Location: enter_job_successfully.htm');
    } else {
    echo 
    'Error executing ' $sql ' due to ' mysql_error();

    and replace it with
    PHP Code:
    header('Location: enter_job_successfully.htm'); 
    and add this to the end of all of your mysql_query() lines:
    PHP Code:
    or die(mysql_error()); 

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Absolutely perfect - thanks so much!!

    I will endeavour to add the line you suggest to all my Mysql_query lines!!


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
  •