我收到此错误 警告:mysqli_error()正好需要1个参数,给出0 我不明白为什么我的代码会被吹到这里
<?php
// display add blog script and insert query
} else {
if(isset($_POST['submit']))
{
$heading = htmlentities($_POST['heading']);
$description = htmlentities($_POST['description']);
$heading = str_replace(' ', '-', $heading);
$cat_name = $_POST['blog_cat'];
$fileToUpload = basename($_FILES['fileToUpload']['name']);
$target_dir = "uploads/blog/";
$target_file = $target_dir.$fileToUpload;
$db_insert_image = "company_profile/".$target_file;
$date = date("y-m-d");
$query = mysqli_query($conn, "INSERT INTO blog SET heading='$heading',
description='$description', blog_cat='$cat_name', image='$db_insert_image',
author='$ename', status='1', created_date='$date'");
if ($query) {
if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],$target_file)) {
echo "<script>alert('Image uploaded.')</script>";
header("location:manageBlog.php");
exit();
} else {
echo "<script>alert('There was a problem uploading image.')</script>";
}
} else {
echo mysqli_error();
echo "<script>alert('There was a problem with query, please try again.')
</script>";
}
}
&GT;
答案 0 :(得分:0)
用此替换$ query语句并删除mysqli_error()行。 如果有任何错误,它将自动运行mysqli_error()。
$query = mysqli_query($conn, "INSERT INTO blog SET heading='$heading',
description='$description', blog_cat='$cat_name', image='$db_insert_image',
author='$ename', status='1', created_date='$date'")
or die(mysqli_error($conn));
答案 1 :(得分:0)
您应该将 mysqli_error(); 更改为 mysqli_error($ conn);
有关此功能的更多信息enter link description here