I'm trying to output something like, if user exists in the database then they can't register but I'm getting an error, it returns false instead of an actual result, I don't understand why.
Here's my connector function
public function db_connect(){
$db_connect = mysqli_connect(
$this->db_host,
$this->db_user,
$this->db_pass,
$this->db_name
);
if (mysqli_connect_errno($db_connect)) {
echo "<font color='red'>"."Failed to connect to MySQL: " . mysqli_connect_error() ."</font></br>";
}
return $db_connect;
}
Here's where the validation goes.
public function testtable_add($Testtable1, $Testtable2, $Testtable3, $Flag){
#$Id = $this->id;
$this->testtable1 = $Testtable1;
$this->testtable2 = $Testtable2;
$this->testtable3 = $Testtable3;
$this->flag = $Flag;
$connector = new connector();
$query = "SELECT * FROM testtable WHERE testtable1 = $Testtable1";
$result = mysqli_query($connector->db_connect(), $query);
while($row = mysqli_fetch_assoc($result)){
if($result->num_rows){
echo "Data exists!";
} else {
$query = "INSERT INTO test_table (testtable1, testtable2, testtable3, flag) VALUES ('$this->testtable1','$this->testtable2','$this->testtable3', '$this->flag')";
}
}
}
The error occur upon insertion of data.
Aucun commentaire:
Enregistrer un commentaire