我正在尝试使用 MySQLi 将一些数据插入到 MySQL 数据库中,我已连接到数据库,但页面为空白,MySQL 数据库为空。有什么想法吗?
<?php
$mysqli = new mysqli('localhost', '***', '***', '***');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
session_start();
$stmt = $mysqli->prepare("INSERT INTO membersinfo VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param('ssssssssssssssssssssssssssssssss', $_SESSION['fullname'], $_SESSION['sex'], $_SESSION['dob'], $_SESSION['nameofparent'], $_SESSION['address1'], $_SESSION['address2'], $_SESSION['city'], $_SESSION['postcode'], $_SESSION['homephone'], $_SESSION['mobilephone'] ,$_SESSION['workphone'], $_SESSION['email'], $_SESSION['email2'], $_SESSION['contactname'], $_SESSION['relation'], $_SESSION['phonenumber'], $_SESSION['med'], $_SESSION['disability'], $_SESSION['typeofdis'], $_SESSION['natureofdis'], $_SESSION['sport'], $_SESSION['wheresport'], $_SESSION['friends'], $_SESSION['sign1'], $_SESSION['con1'], $_SESSION['date1'], $_SESSION['sign2'], $_SESSION['con2'], $_SESSION['date2'],$_POST['sign3'], $_POST['con3'], $_POST['date3']);
/* execute prepared statement */
$stmt->execute();
printf("%d Row inserted.\n", $stmt->affected_rows);
/* close statement and connection */
$stmt->close();
/* close connection */
$mysqli->close();
?>
最佳答案
你有 32 个?和 33 个值。因此,您会收到以下 mysql 错误或类似错误,
MySQL error: Column count doesn't match value count
如果您想查看错误,请将其包含在您的代码中
error_reporting(E_ALL);
ini_set('display_errors', 1);
关于php - MySQLi 空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29333813/