2

I'm writing the php code which linked with database.

If I put the value on the php code for example

$pid = somevalue.

this some value will pass it to the next php file.

and I want to check this somevalue is not empty or not a string value

if( some condition ){

printf("Invalid input: %s\n", mysqli_connect_error());
echo "<br/><a href='index.php'>Back to previous page</a>";
exit();
}
0

4 Answers 4

1

use

if (!empty($pid) && is_numeric($pid)) {
    // proceed
} else {
    // error
}
Sign up to request clarification or add additional context in comments.

Comments

1
$pid  = (int) $pid;
if ($pid) {
} else {
}

1 Comment

What will this do if $pid is 0?
0

Just define it as spoken

if ( ! empty($foo) && ! is_string($foo) ) {

}

Comments

0
if(!empty($pid) and !is_string($foo)){
   printf("Invalid input: %s\n", mysqli_connect_error());
   echo "<br/><a href='index.php'>Back to previous page</a>";
   exit();
}

1 Comment

empty will also be true if a variable contains 0.

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.