我花了好几个小时试图找出问题,但没有运气:/ 我正在运行此查询:
if($_POST) {
$ask_name = mysqli_real_escape_string($connect, $_POST['ask_name']);
$ask_email = mysqli_real_escape_string($connect, $_POST['ask_email']);
$ask_text = mysqli_real_escape_string($connect, $_POST['ask_text']);
$ask_category = mysqli_real_escape_string($connect, $_GET['categ']);
$ask_time = date("d-F-Y");
if($ask_name = "" || $ask_email == "" || $ask_text == "" || $ask_category == "") {
$msg = '<span class="fa fa-exclamation-triangle fa-lg"></span> Fill Out All Inputs Please';
}
else {
$insert_post = mysqli_query($connect, "INSERT INTO forum_posts (name, email, text, category, time) VALUES ('$ask_name', '$ask_email', '$ask_text', '$ask_category', '$ask_time')");
header('Location: forum.php?categ=' .$ask_category);
exit();
}
}
这是我的php文件中的表单
<!--Insert Post-->
<form id="ask-question" method="post" name="ask_question" action="">
<label for="ask-name">Your Name</label><br>
<input type="text" name="ask_name" id="ask-name"><br>
<label for="ask-email">Your E-Mail (Won't be displayed)</label><br>
<input type="email" name="ask_email" id="ask-email"><br>
<label for="ask-text">Your Question</label><br>
<textarea name="ask_text" id="ask-text"></textarea><br>
<input type="submit" name="post_submit" value="Ask Now" id="post-submit">
<?php if(isset($msg)) { echo('<p>' .$msg. '</p>'); } ?>
</form>
问题是查询没有插入&#34;名称&#34;值。所有其他值都成功插入到我的mysql数据库中,但是&#34; name&#34;价值。
有什么想法吗?非常感谢你!
答案 0 :(得分:4)
您在=
条件中使用了单if
符号而非双倍。
更改
if($ask_name = ""...
到
if($ask_name == ""...
^
否则您将空字符串分配给该变量
答案 1 :(得分:0)
$ask_name = ""
表示您正在为该变量分配空值。
更改
if($ask_name = "" || $ask_email == "" || $ask_text == "" || $ask_category == "")
到
if($ask_name == "" || $ask_email == "" || $ask_text == "" || $ask_category == "")