php - Why does mysqli_num_rows always return 0? -


i want check input of user after hits submit button if word exist in database.

hence, have code. however, says data not exist in finds condition false.

what wrong code below?

$input_word = trim($_post["word"]); $data_check = "select * word_collections single_word = '$input_word'"; $a = mysqli_query($data_check); if (mysqli_num_rows($a) == 1) {     echo "data exist."; } else {     echo "data not exist"; } 

your query failed because didn't pass db connection to:

$a = mysqli_query($data_check); 

the variable connection unknown, need base on:

$a = mysqli_query($connection, $data_check); 

and may have use >0 instead of ==1 num_rows() there more 1 record.

your code open sql injection; use prepared statement.

use php's error reporting , mysqli_error($connection) on query.

also make sure connection in fact mysqli_ , not api.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -