Преобразовано в строку Ошибка

Ловимая фатальная ошибка:

Объект класса mysqli_result не может быть преобразован в строку в строке: 99

Как решить эту ошибку?

<?php

class DB_con
{

private $servername;
private $user;
private $password;
private $dbname;
public $connection;

public function __construct()
{
$this->db_connect();
}

public function db_connect()
{
$this->servername = "localhost:3307";
$this->user = "root";
$this->password = "1234";
$this->dbname = "library";

$this->connection = new mysqli($this->servername,$this->user,$this->password,$this->dbname);

if($this->connection->connect_error)
{
die("connection failed :".$this->connection->connect_error);
}
else
{
echo "Success";
}
return $this->connection;
}

public function insert($user,$hide,$phone,$address,$posting,$date,$secu_ques,$secu_ans)
{
$this->db_connect();

/*if($pass != $rpass)
{
echo "<script>
alert('The Passwords do not match');
</script>";
}*/$phone = mysqli_query($this->connection,"SELECT Phone from Users WHERE Phone = '$phone'");

$get_phone = mysqli_affected_rows($this->connection);

if($get_phone >1)
{
echo "<script>
alert('Number already Exists!!!');
</script>";
}

else if($address == null)
{
echo "<script>
alert('Fill out all the Fields to Continue');
</script>";
}

else if($posting == 'Designation')
{
echo "<script>
alert('Choose a Designation!!!');
</script>";
}

else if ($secu_ques == null || $secu_ans == null)
{
echo "<script>
alert('Enter A Security Question and Answer to Continue');
</script>";
}

else
{

$select_user = "SELECT Username from Users WHERE Username = '$user'";
mysqli_query($this->connection,$select_user);

$get_user = mysqli_affected_rows($this->connection);

if($get_user >=1)
{
echo "<script>
alert('This Username Already Exists!!!');
</script>";
}

else
{

$record_add = "INSERT INTO Users(Username,Password,Phone,Address,Designation,DOJ,Question,Answer)VALUES('$user','$hide','$phone','$address','$posting','$date','$secu_ques','$secu_ans')";
$res = mysqli_query($this->connection,$record_add);

if($res == TRUE)
{
echo "<script type = 'text/javascript'>
alert('Congrats you have Successfully Registered!!!');
</script>";
}

else
{
echo "<script type = 'text/javascript'>
alert('Error in Registering!!!');

</script>";
}

}

}
}}

?>

-1

Решение

Ваша переменная $ phone перезаписывает исходную переменную. Попробуй это:

менять

$phone = mysqli_query($this->connection,"SELECT Phone from Users WHERE Phone = '$phone'");

в

$phone_exist = mysqli_query($this->connection,"SELECT Phone from Users WHERE Phone = '$phone'");
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector