Cannot find my error!

Discussion in 'PHP' started by mokimofiki, Feb 4, 2009.

  1. #1
    The Error that I am recieving is:
    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 '' at line 1

    The code that is erroring is:
    <?php
    session_start();
    include('globals.php');
    include('header.php');
    include('toplinks.php');
    
    if($_SESSION['uid']){
        
        $sql1 = "SELECT * FROM `dirsubmit_account` WHERE `accid`=".$SESSION['uid']."";
        $res1 = mysql_query($sql1) or die(mysql_error());
        $row1 = mysql_fetch_assoc($res1);
    
        $sql2 = "SELECT * FROM `dirsubmit_directories` WHERE `dirid`=".$res1['accsubmissions']."";
        $res2 = mysql_query($sql2) or die(mysql_error());
        $row2 = mysql_fetch_assoc($res2);
    
    
    
        echo "<table width=\"800\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
        echo "<tr>";
        echo "<td valign=\"top\"><iframe src=".$row2['dirurl']." height=\"500\" width=\"650\"></iframe></td>";
        echo "<td valign=\"top\" id=\"rightnavinfo\">Info for Submission:<br /></td>";
        echo "</tr>";
        echo "</table>";
    
    }else{
        echo "You must login to complete this action!<br /><br />Please <a href=\"login.php\">click here</a> to login!";
    }
    ?>
    Code (markup):
    I only recieve the error after I login .... If i'm not logged in then it goes to the else just fine?

    Any thought's?
     
    mokimofiki, Feb 4, 2009 IP
  2. teamtnk229

    teamtnk229 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hi,

    i think problem lies in the $sql2 query statement

    please put $row1['accsubmissions'] instead of $res1['accsubmissions']

    and also try put condition or check $row1['accsubmissions'] is null or not before working on sql2 query
     
    teamtnk229, Feb 4, 2009 IP
  3. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #3
    mokimofiki, Feb 4, 2009 IP
  4. Femto

    Femto Peon

    Messages:
    23
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    it worked for me logging using test
     
    Femto, Feb 4, 2009 IP
  5. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #5
    once you actually logged in and said continue to directory submission it worked?

    Ah I see you never clicked on the continue button after logging in .... the login and registration works fine its after you login and try to get to the actual member area that gives the SQL error.
     
    mokimofiki, Feb 5, 2009 IP
  6. Acecool

    Acecool Peon

    Messages:
    267
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Comment one of the queries out, one or the other is making the error...

    Then go through it...


    Ill recode these real quick

        $sql1 = 'SELECT * FROM dirsubmit_account WHERE accid="' . $SESSION['uid'] . '"';
        $res1 = mysql_query($sql1) or die(mysql_error());
        $row1 = mysql_fetch_assoc($res1);
    
        $sql2 = 'SELECT * FROM dirsubmit_directories WHERE dirid="' . $res1['accsubmissions'] . '"';
        $res2 = mysql_query($sql2) or die(mysql_error());
        $row2 = mysql_fetch_assoc($res2);
    
    Code (markup):
     
    Acecool, Feb 5, 2009 IP
  7. xrachel.louisex

    xrachel.louisex Peon

    Messages:
    138
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I think you're missing an underscore in your query too ($sql1)

    $SESSION['uid'] ---> $_SESSION['uid']
     
    xrachel.louisex, Feb 5, 2009 IP
    mokimofiki likes this.
  8. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #8
    Ah thank you so much I figured it was just something I was overlooking.

    +rep
     
    mokimofiki, Feb 5, 2009 IP