我正要解決這個問題。我的代碼中的一行似乎正在起作用。它返回與其他人似乎並不想運行它。它沒有錯誤,但它不會將其移動到數據庫。正如標題所說,這是一個if語句中的mysqli_query。這裏是代碼,我已經把箭頭放在錯誤似的地方。mysqli_query不能在If語句中工作
$t_name = $_POST['topic_name'];
$content = $_POST['con'];
$date = date("y-m-d");
if(isset($_POST['submit'])) {
if($t_name && $content) {
if(strlen($t_name) >= 10 && strlen($t_name) <= 70) {
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
if($query = mysqli_query($connect, "INSERT INTO topics('topic_id', 'topic_name', 'topic_content', 'topic_creator', 'date') VALUES ('', '".$t_name."', '".$content."', '".$_SESSION["username"]."', '".$date."')")) {
echo "<font color = 'green'>Topic posted!</font>";
} else {
echo "<font color='red'>Unknown failure, time to panic!</font>";
}
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
} else {
echo "<font color='red'>Topic name must be between 10 and 70 characters long!</font>";
}
} else {
echo "<font color='red'>All fields must be filled out!</font>";
}
}
} else {
include('header.php');
echo "You must be logged in to access this page. Click <a href='login.php'>here</a> to login.";
}
include('footer.php');
是的,我知道SQL注入和其他事情的危險,一旦我有我的代碼關閉,我會處理它。
您是否嘗試從插入中刪除主題ID列? –
哦,離開mysql處理日期!使用「now()」功能! https://dev.mysql.com/doc/refman/5.5/zh-CN/date-and-time-functions.html#function_now –
@HizerCache從來不知道,謝謝! – SkrillexNukehulk