This is quite strange, the query executes just fine and inserts the data into the table, but my affected rows shows on the negative side rather than 1. Does anyone know why this is happening?
connect.php:
<?php
error_reporting(0);
$db = new mysqli('localhost', 'root', 'pass', 'db');
?>
here is the main code:
<?php
include 'connect.php';
include 'blowfish.php';
if($_POST['email'] == true)
{
if($db -> connect_errno)
{
echo "Could not connect to the database, please try again later...";
}
else
{
$email = $_POST['email'];
$query = "SELECT id FROM users WHERE email = ?";
$statmnt = $db -> prepare($query);
$statmnt-> bind_param("s",$email);
$statmnt-> execute();
$statmnt-> bind_result($result);
$statmnt-> fetch();
$statmnt-> reset();
if($result)
{
$id = $result;
$result = "";
$randomString = generateRandomString(50); // Generate random string
$query = "UPDATE users SET emailString = ? WHERE id =?";
$statmnt= $db -> prepare($query);
$statmnt-> bind_param("si",$randomString,$id);
$statmnt-> execute();
$statmnt-> bind_result($result);
$statmnt-> fetch();
$statmnt-> reset();
$test = $db -> affected_rows;
echo $test;
}
else
{
echo "That Email Address is not registered...";
}
}
}
else
{
echo "No Email received...";
}
?>
$test returns "-1"
You should get affected_rows
value before you call reset()
or close()
function on $statmnt
.