尝试使用此表单将新数据添加到我的数据库中但由于某种原因它似乎不起作用?它不是停留在同一页面“admin.php?page = 3”,而是重定向到“admin.php”而没有回声或标志它甚至做了什么?有人可以帮帮我吗?干杯!
表格:
<form>
<form name="postnewstory" action="admin.php?page=3" method="POST">
<strong>News Title: </strong><input type="text" name="news_title"><br><br />
<strong>News Story:</strong><br>
<textarea name="news_body" rows="4" cols="60"></textarea><br><br />
<input type="file" name="news_photo"><br>
<strong>Story Link: </strong><br />
<input name="button" type="radio" value="0" checked="checked">No Link<br>
<input type="radio" name="button" value="1">Link<br><br />
<strong>Link Address: </strong><input type="text" name="news_link"><br>
<strong>News Story Tags: </strong><input type="text" name="news_tags">
<input type="submit" value="Post" name="postnewstory" class="btn btn-success"><br />
</form>
PHP: 我知道它非常基本,只是在我添加错误检查之前尝试让它工作。
<?php
if (isset($_POST['postnewstory'])){
$username = $user_data['username'];
$email_address = $user_data['email_address'];
$news_title = $_POST['news_title'];
$news_photo = $_POST['news_photo'];
$button = $_POST['button'];
$news_link = $_POST['news_link'];
$news_tags = $_POST['news_tags'];
$exists = mysql_query ("SELECT * FROM users WHERE username='$username'") or die ("not found");
if (mysql_num_rows($exists) != 0){
//update the info in database
mysql_query ("INSERT INTO news (`news_id` ,`news_title` ,`news_body` ,`news_photo` ,`news_date` ,`username` ,`news_tags` ,`button ,`news_link`)
VALUES (NULL , '$news_title', '$news_body', '$news_photo', now(), '$username', '$news_tags', '$button', '$news_link');") or die ("update didn't work");
echo "<div class='alert alert-success'><strong>This post was sent!</strong></span></div> ";
echo '<meta http-equiv="refresh" content="2;url=admin.php?page=3">';
} else echo "<strong><font color=red>Update did not work, please try again.</font></strong>";
}
?>
答案 0 :(得分:1)
你的反复缺失:
,`button
更改为:
,`button`
重写:
("INSERT INTO news (`news_id` ,`news_title` ,`news_body` ,`news_photo` ,`news_date` ,`username` ,`news_tags` ,`button`,`news_link`)
<强>脚注:强>
我引用Shankar
:
“将die ("update didn't work");
替换为die (mysql_error());
以了解您的查询无效的确切错误。”
答案 1 :(得分:0)
我认为这应该有用; 改变行
echo '<meta http-equiv="refresh" content="2;url=admin.php?page=3">';
到
echo "<script>window.location = 'admin.php?page=3';</script>";