将图像名称和编号插入数据库

时间:2016-11-22 11:07:49

标签: php android

我不断收到类mysqli的对象无法转换为字符串的错误。

以下是在数据库中插入图像名称和编号的代码:

<?php
$servername = "localhost";
$username = "u785741983_boy";
$password = "789456";
$dbname = "u785741983_tuner";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection

if ($conn->connect_error) {
   echo "Connection Error";
    die("Connection failed: " . $conn->connect_error);
} 

$image = base64_decode($_POST['image']);
$number = $_POST['number'];
$name = $_POST['name'];
$sql = "INSERT INTO `Person`(`Picture`,'Name','Number') VALUES ('$image','$name','$number')";

if ($conn->query($sql) === TRUE) {
    echo $sql;
} else {
    echo $conn;
}

$conn->close();
?>

1 个答案:

答案 0 :(得分:0)

你不能在else语句中执行echo mysqli_connect_error(),因为连接是一个对象。

哟必须echo $conn->connect_error()或{{1}}

查看http://php.net/manual/en/mysqli.connect-error.php