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 2 of 2
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Query not throwing proper error

    I have the following code that is not throwing an error like I am used to...

    PHP Code:
        // Build query.
        
    $q2 "SELECT MAX(comment_no) AS lastCommentNo
                FROM comment
                WHERE article_id=?"
    ;

        
    // Prepare statement.
        
    $stmt2 mysqli_prepare($dbc$q2);

        
    // Bind variable to query.
        
    mysqli_stmt_bind_param($stmt2'i'$articleID);

        
    // Execute query.
        
    mysqli_stmt_execute($stmt2);

        
    // Store results.
        
    mysqli_stmt_store_result($stmt2);

        
    // Check # of Records Returned.
        
    if (mysqli_stmt_num_rows($stmt2)==1){
            
    // Maximum Found.

            // Bind result-set to variables.
            
    mysqli_stmt_bind_result($stmt2$lastCommentNo);

            
    // Fetch record.
            
    mysqli_stmt_fetch($stmt2);

            
    // Increment CommentNo.
            
    $commentNo $lastCommentNo 1;

        }else{
            
    // Maximum Not Found.
            
    $_SESSION['resultsCode'] = 'COMMENT_MAXIMUM_NOT_FOUND_2049'

    Normally to test the "Error Branch" of my code above, I would change $articleID to $articleID2, thus breaking my query and launching the ELSE branch of my code with the Error-Message.


    The problem seems to be that $articleID2=0 and so my query returns a NULL for the MAX() which technically counts as a row being returned?!

    Follow me?!

    That isn't the behavior I am looking for.



    Debbie

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    how about
    PHP Code:
    $q2 "SELECT MAX(comment_no) AS lastCommentNo
                FROM comment
                WHERE article_id='debbie'"



  •  

    Posting Permissions

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