我正在编写数据库应用程序,但php配置告诉我:
警告:mysqli_execute()期望参数1为mysqli_stmt, 给定布尔值
我的add.php文件如下所示:
$conn=mysqli_connect ($server, $user, $password, $db);
if ( !$conn ) {
die( 'connect error: '.mysqli_connect_error() );
}
$value1 = $_POST['country'];
$value2 = $_POST['station'];
$value3 = $_POST['stream'];
$value4 = $_POST['stream2'];
$value5 = $_POST['web'];
$value6 = $_POST['genre'];
$value7 = $_POST['desc'];
$query = mysqli_prepare($conn, 'INSERT INTO `stations`(`station`, `country`, `stream`, `stream2`, `web`, `genre`, `desc`)
VALUES ($value1,$value2,$value3,$value4,$value5, $value6,$value7)');
$stmt1 = mysqli_prepare($conn, $query);
/*mysqli_bind_param($query, "sssssss", $value1, $value2, $value3, $value4, $value5, $value6, $value7);*/
mysqli_execute($query);
if ( !mysqli_execute($stmt1) ) {
die( 'stmt error: '.mysqli_stmt_error($stmt1) );
}
/*header("Location: index.php");
echo '<script type="text/javascript">';
echo 'alert("your station was added!")';
echo '</script>';*/
答案 0 :(得分:0)
请试试这个:
if (!mysqli_query($conn,'INSERT INTO `stations`(`station`, `country`, `stream`, `stream2`, `web`, `genre`, `desc`)
VALUES ($value1,$value2,$value3,$value4,$value5, $value6,$value7)'))
{
echo("Error description: " . mysqli_error($con));
}
删除所有其他编码
答案 1 :(得分:0)
$conn = mysqli_connect ($server, $user, $password, $db);
if ( !$conn ) {
die( 'connect error: '.mysqli_connect_error() );
}
$value1 = $_POST['country'];
$value2 = $_POST['station'];
$value3 = $_POST['stream'];
$value4 = $_POST['stream2'];
$value5 = $_POST['web'];
$value6 = $_POST['genre'];
$value7 = $_POST['desc'];
if ($stmt = $conn->prepare("INSERT INTO stations (station, country, stream, stream2, web, genre, 'desc') VALUES (?, ?, ?, ?, ?, ?, ?")) {
$stmt->bind_param('sssssss'. $value1, $value2, $value3, $value4, $value5, $value6, $value7);
if ($stmt->execute() !== false) {
// YAY
} else {
// Doesn't work
}
}
准备好的陈述让您的生活更轻松。这应该按你的意愿工作:)