Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: sql error

  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sql error

    hi all,
    i have tried doing something like a page browser where u have page numbers on top. and each page containing a maximum amount of contents.u will understand if u see the code and here it is:

    PHP Code:
    switch ($_GET["mode"])
        {
            case 
    "list":
              
    $sql "SELECT * FROM tblgallery username = '" .$_POST["txtUserID"] . "'";
                
    $rs mysql_query($sql);
                
    $nRows mysql_num_rows($rs);
                
                
    /*    Set the default records to be shown per page as 5    */
                
    $pageSize 6;
                
                
    /*    Page is not set then set it to page 1    */
                
    if(!isset($_GET["page"])) 
                    
    $page 1;
                else
                    
    $page $_GET["page"];
                
                
    $startPos $page $pageSize - ($pageSize);    // Ex: (2 * 10) - 10 = 10 <- data starts at 10
                
    $sql .= ' LIMIT ' $startPos ', ' $pageSize;    //now break into paged sections
                
    $rs mysql_query($sql) or die('Error: ' mysql_error());
                
                
                    
                echo(
    '<table width="100%" cellspacing="2" border="0" align="center" cellpadding="2">');
                echo(
    '    <tr><td align=right><span class="nav">');
                
                if (
    $page != 1) {
                    
    $prev $page 1;
                    echo 
    '<span class="nav"><a href="' $_SERVER['PHP_SELF'] . '?mode=list&page='.$prev.'">&lt;&lt;</a>';
                }
                else
                    echo (
    "<span class=\"nav\">&lt;&lt;");
                
                
    $totalPage $nRows $pageSize;
                for(
    $i 1$i <= $totalPage$i++) {
                    
    /*    inactive page, don't add linking    */
                    
    if ($i == $page){ echo '&nbsp;' $i;}    
                    
    /*    page active, add linking    */
                    
    else {echo '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $i '">' $i '</a>';}
                }

                if ((
    $nRows $pageSize) != 0) {
                    
    /*    inactive page number    */
                    
    if ($i == $page){ echo '&nbsp;' $i; }
                    
    /*    active page, linked    */
                    
    else {echo '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $i '">' $i '</a>'; }
                }

                if( (
    $nRows - ($pageSize $page)) > 0) {
                    
    $next $page 1;
                    echo 
    '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $next '">&gt;&gt;</a></span>';
                }    
                else{
                    echo 
    "&nbsp;&gt;&gt;</span>";
                    echo(
    "</td>");
            echo(
    "</tr>");
          echo(
    "</table>");
                
            echo(
    '<table width="100%" border="0" cellspacing="1" cellpadding="4">');
                     while (
    $row mysql_fetch_object($rs)) { 
              echo(
    "<tr><td align=center class=\"bg\" border=1><img src=\"$row->pic_Path\" width=\"150\" height=\"120\"></td>
                            <td align=center border=1><img src=\"$row->pic_Path\" width=\"150\" height=\"120\"></td></tr>"
    );
             
    /* echo('<tr>
                <td align=center><img src="$row->pic_Path" width="150" height="120"></td>
                            <td align=center class="bg"><img src="$row->pic_Path" width="150" height="120"></td>
              </tr>');
              echo('<tr>
                <td align=center class="bg"><img src="$row->pic_Path" width="150" height="120"></td>
                            <td align=center ><img src="$row->pic_Path" width="150" height="120"></td>
              </tr>');*/
       
    }//close while 
    now the problem which i dun see is here:

    PHP Code:
     $sql "SELECT * FROM tblgallery username = '" .$_POST["txtUserID"] . "'";
                
    $rs mysql_query($sql);
                
    $nRows mysql_num_rows($rs); 
    and here
    PHP Code:
    $startPos $page $pageSize - ($pageSize);    // Ex: (2 * 10) - 10 = 10 <- data starts at 10
                
    $sql .= ' LIMIT ' $startPos ', ' $pageSize;    //now break into paged sections
                
    $rs mysql_query($sql) or die('Error: ' mysql_error()); 
    getting these warnings and error:

    Notice: Undefined index: txtUserID in c:\program files\apache group\apache\htdocs\ewedding\photoupload.php on line 199

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\ewedding\photoupload.php on line 201
    Error: You have an error in your SQL syntax near '= '' LIMIT 0, 6' at line 1
    i tried figuring whats the problem...so...but i can't see what's wrong...hope someone can help me.tahnks
    Warm Regards,
    Mivec

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you need to have a WHERE in your sql-condition (see one of your other threads). So change the selects to
    PHP Code:
    $sql="SELECT * FROM tblgallery WHERE username = '".$_POST["txtUserID"]."'"
    About the notice --> see one of your other threads or run a search here for errorhandling or errorreporting
    Last edited by raf; 04-13-2004 at 03:15 PM.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks raf for helping but i still don't get u..i mean, i practically see the same thing as i have posted. what's the * for?
    Warm Regards,
    Mivec

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The * got added by the forum for some reason ...

    the difference is that you need to have a 'WHERE' at the start of your condition.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

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