0

I got problem with simple insert data to table.

I got this code:

// Create connection
$dbConnection = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($dbConnection->connect_error) {
    die("Connection failed: " . $dbConnection->connect_error);
}

//Check if keyword exist
$keyword = "test";
$stmt = $dbConnection->prepare('SELECT keyword FROM keywords WHERE keyword=?');
$stmt->bind_param('s', $keyword);
$stmt->execute();
echo 'good';

$rowCount = $stmt->num_rows;

if($rowCount <= 0) {
    echo 'rekord nie istnieje';
    //if not add new one

    $keyword = "test";
    $stmt = $dbConnection->prepare('INSERT INTO keywords (keyword) VALUES (?)');    

    $stmt->bind_param('s', $keyword);
    $stmt->execute();
}

SELECT query works fine, num_row counting too, but insert to db not i got error:

PHP Fatal error:  Call to a member function bind_param() on boolean in

of is going about line $stmt->bind_param('s', $keyword); of insert query.

pls some advice, table got id(A_I)(INT 11) and keyword(VARCHAR 100).

Barmar
  • 669,327
  • 51
  • 454
  • 560

0 Answers0