<?php include"dbconn.php";
if(isset($_POST["submit_image"])){
$imgdate = $_POST["image_date"];
$imgalbum = $_POST["image_album"];
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check != false){
$image = $_FILES['image']['tmp_name'];
$imgContent = addslashes(file_get_contents($image));
$insert = "INSERT INTO image_db (img_pic, img_date, img_album) VALUES ('$imgContent', '$imgdate', '$imgalbum')";
$result = mysqli_query($conn,$insert);
//check if the row were updated
if (mysql_affected_rows($result)>0){
echo "File uploaded successfully.";
}else{
echo "File upload failed, please try again.";
}
}else{
echo "Please select an image file to upload.";}}?>
我称之为upload.php的顶级php文件
我称之为upload.html的底部
表单将在upload.html上,然后当用户点击它时将重定向到upload.php
我的dbconn.php已连接到表
<!DOCTYPE html>
<head>
<title>Upload picture</title>
</head>
<body>
<form method="POST" action="upload.php" enctype="multipart/form-data">
<input type="file" name="image">
<label for="text">Image Date :</label>
<input type="text" name="image_date">
<label for="text">Image Album:</label>
<input type="text" name="image_album">
<input type="submit" name="submit_image" value="Upload">
</form>
</body>
</html>
我坚持到这里并继续说我的mysql_affected_rows()期望参数1是资源,给定布尔值 并继续无法上传
答案 0 :(得分:1)
试试这个: mysqli_affected_rows ,没有 mysql_affected_rows
在将数据发送到mysql服务器之前,您需要使用 filter_input 。 http://php.net/manual/en/function.filter-input.php
$insert = "INSERT INTO image_db (img_pic, img_date, img_album) VALUES ('" . $imgContent . "', '" . $imgdate ."', '" . $imgalbum . "')";