PHP-MYSQL, SELECT WHERE CLAUSE Help ?

Discussion in 'PHP' started by qualityhostings, Jan 23, 2009.

  1. #1
    Hello

    I am stuck in this step

    $result = mysql_query("SELECT id FROM tblmarks WHERE reg_no = '$reg_no' AND year = '$year' AND sem = '$sem'");


    This is not working for me.

    I want to take the value of id , from the table tblmarks with these conditions

    reg_no should be eqal to $reg_no
    year = $year
    sem = $sem

    I dont know why this syntax is not working ?
    Anybody can help me ?

    Thanks
     
    qualityhostings, Jan 23, 2009 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    It looks like you have an errant comma before your first AND.
     
    joebert, Jan 23, 2009 IP
  3. qualityhostings

    qualityhostings Well-Known Member

    Messages:
    1,764
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    105
    #3
    But it is still not working
    ?


    $result = mysql_query("SELECT id FROM tblmarks WHERE reg_no = '$reg_no' AND year='$year' AND branch='$branch'");
     
    qualityhostings, Jan 23, 2009 IP
  4. qualityhostings

    qualityhostings Well-Known Member

    Messages:
    1,764
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    105
    #4
    Ok, I found the problem, It was with the mysql table. The year value was not there.
    When I added it , the problem solved.
     
    qualityhostings, Jan 23, 2009 IP
  5. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #5
    That's good, because I wasn't seeing anything else wrong with the query. :)
     
    joebert, Jan 23, 2009 IP