Results 1 to 3 of 3
  1. #1
    Join Date
    May 2008


    please can someone help me with this query. It says there is syntax error with my select statement

    $exam = $_GET['ex'];
    $cur = $_GET['cur'];
    $tp = $_GET['tps'];

    mysql_select_db($database_ecertConn, $ecertConn);
    $query_Recordset1 = "SELECT topics.topic, FROM topics WHERE excode='$exam' cocode='$cur' AND tpcode='$tps' ";
    $Recordset1 = mysql_query($query_Recordset1, $ecertConn) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    please don't hijack a thread, if its a new question start a new thread
    if its a PHP problem ask it in the PHP forum

    I thought MySQL used the " to delimit strings
    you are also missing and AND int he where clause
    and you are also missing the terminating semicolon
    $query_Recordset1 = "SELECT topics.topic, FROM topics WHERE excode=\"$exam\ AND" cocode=\"$cur\" AND tpcode=\"$tps\";" ;
    Whenever you have problems with SQL, especially if you are building the SQL using parameters or variables from elsewhere it generally pays to display the sql somewhere so you can make sure what you are sending to the SQL engine is actually what you think it is. It also helps if you assing the SQL to a variable (say $strSQL).

    you could do this using the or die construct

    or die(echo " The SQL is:".$strSQL; )

    some people prefer to separate the lines so its easier to read
    $query_Recordset1 = "SELECT topics.topic, FROM topics
     WHERE excode="$exam"
     AND cocode="$cur'
     AND tpcode="$tps";";
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jun 2008
    You are missing an AND between '$exam' and cocode. The correct statement should be:

    $query_Recordset1 = "SELECT topics.topic, FROM topics WHERE excode='$exam' AND cocode='$cur' AND tpcode='$tps' ";

Posting Permissions

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