php - error: mysqli prepared insert statement -


i have table tag. in table there 2 fields id & tag. using mysqli prepared statement insert in db.

here codes.

$search='test'; // prepared query    $result = $mysqli->prepare("select tag tag tag= ?");             $result ->bind_param("s", $search);             $result->execute();             $result->store_result();              $result->bind_result($search);         while ($result->fetch()) {             $tag = $tag;        }                  if($result->num_rows != 1){                      echo "test";                     $result1 = $mysqli->prepare("insert tag (tag) values (?)");                 $result1 ->bind_param("s", $search);                     $result1->execute();                     $result1->store_result();          if($result1->affected_rows == 1){              //$res['success'] = true;             $data[] = "added successfully";           }                       }  // return result in json echo json_encode($data); 

for reason not working. have added db.php file.

it working fine till here if($result->num_rows != 1){ because echo test there , getting output.

i know there silly mistake have done don't know where. please me find out.

you have close connection :

$result->close(); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -