2

How can i check the result of my query? I try this, but when the result is empty - error doesn't shows.

$result = sqlite_query($db, "SELECT * FROM catalog WHERE cat=".$_GET["cat"]." AND size".$size.""); 
        if($result !== 0) {
            while ($row = sqlite_fetch_array($result)) { 
                echo '<img src="'.$row['img1'].'" alt="'.$row['id'].'" />'."\r\n"; 
            } 
        } else {
            err2();
        }

3 Answers 3

1

Note that sqlite_fetch_array() returns a result handle, not the number of rows, so you should not compare it against zero:

This function will return a result handle or FALSE on failure.

Use sqlite_num_rows() to determine the number of rows returned, e.g.

if(sqlite_num_rows($result) !== 0) {
  ...
} else {
  ...
}

Note that you should not use user-provided data by directly incorporating it in the SQL query as that allows for SQL injection attacks. Also, make sure that the contents of your database, particularly values in columns img1 and id are properly escaped or you risk being vulnerable to XSS attacks.

Sign up to request clarification or add additional context in comments.

Comments

1

You could check number of returning rows using sqlite_num_rows() function

http://www.php.net/manual/en/function.sqlite-num-rows.php

Comments

1

Looks on http://php.net/manual/en/function.sqlite-num-rows.php

$rows = sqlite_num_rows($result);

where $rows will be 0 if the result is empty

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.