我的陈述有什么问题
What is wrong with my statement
当我提交表单时出现错误:有错误消息 "post was not added"。然后它将进入循环并继续打印。
你能看到错误吗:
真的很烦人,每次都差点把我的新鲜事搞砸了。
<?php
$q = "SELECT user_id FROM users WHERE id = $id";
$r = mysqli_query($dbc, $q);
while($vote_list = mysqli_fetch_assoc($r)) { ?>
<?php
if(isset($_POST['submitted']) == 1) {
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = '../uploads'; //2
$text = mysqli_real_escape_string($dbc, $_POST['text']);
$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$uploadfile_type = $_FILES['file']['type'];
$newname = time();
$rand = rand(100,999);
$name = $newname.$rand.'.'.$ext;
//if($_POST['id'] != '')
if(($uploadfile_type !='image/jpeg') && ($uploadfile_type !='image/png')){
echo "Post was not added!";
}else{
echo "Post was added!";
$q = "INSERT INTO votes (user_id, text, image) VALUES ('$vote_list[user_id]', '$text', '$name')";
}
$r = mysqli_query($dbc, $q);
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name']; //3
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; //4
$targetFile = $targetPath. $name; //5
move_uploaded_file($tempFile,$targetFile); //6
}
}
?>
<?php } ?>
查看以下几行:
}else{
echo "Post was added!";
$q = "INSERT INTO votes (user_id, text, image) VALUES ('$vote_list[user_id]', '$text', '$name')";
}
$r = mysqli_query($dbc, $q);
你的 mysqli_query
应该在 else 语句中,像这样:
}else{
echo "Post was added!";
$q = "INSERT INTO votes (user_id, text, image) VALUES ('$vote_list[user_id]', '$text', '$name')";
$r = mysqli_query($dbc, $q);
}
在您的代码中,$r
的值在循环内每次都被重置,因此它变成了无限循环。
当我提交表单时出现错误:有错误消息 "post was not added"。然后它将进入循环并继续打印。
你能看到错误吗:
真的很烦人,每次都差点把我的新鲜事搞砸了。
<?php
$q = "SELECT user_id FROM users WHERE id = $id";
$r = mysqli_query($dbc, $q);
while($vote_list = mysqli_fetch_assoc($r)) { ?>
<?php
if(isset($_POST['submitted']) == 1) {
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = '../uploads'; //2
$text = mysqli_real_escape_string($dbc, $_POST['text']);
$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$uploadfile_type = $_FILES['file']['type'];
$newname = time();
$rand = rand(100,999);
$name = $newname.$rand.'.'.$ext;
//if($_POST['id'] != '')
if(($uploadfile_type !='image/jpeg') && ($uploadfile_type !='image/png')){
echo "Post was not added!";
}else{
echo "Post was added!";
$q = "INSERT INTO votes (user_id, text, image) VALUES ('$vote_list[user_id]', '$text', '$name')";
}
$r = mysqli_query($dbc, $q);
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name']; //3
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; //4
$targetFile = $targetPath. $name; //5
move_uploaded_file($tempFile,$targetFile); //6
}
}
?>
<?php } ?>
查看以下几行:
}else{
echo "Post was added!";
$q = "INSERT INTO votes (user_id, text, image) VALUES ('$vote_list[user_id]', '$text', '$name')";
}
$r = mysqli_query($dbc, $q);
你的 mysqli_query
应该在 else 语句中,像这样:
}else{
echo "Post was added!";
$q = "INSERT INTO votes (user_id, text, image) VALUES ('$vote_list[user_id]', '$text', '$name')";
$r = mysqli_query($dbc, $q);
}
在您的代码中,$r
的值在循环内每次都被重置,因此它变成了无限循环。