我的必填字段有错误,但即使已填写,它也会显示我的错误消息,也许我需要一个 else 语句但不完全确定。
session_start();
// this sets variables in the session
$id = $_SESSION['user_id'];
foreach($_POST as $key => $value)
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$err = array();
$result = mysql_query("SELECT `id` FROM users WHERE `banned` = '0'") or
die (mysql_error());
if(empty($_SESSION['$user_id'])) // user not logged in; redirect to somewhere else
if (!empty($_POST['doThesis']) && $_POST['doThesis'] == 'Save')
{
$result = mysql_query("SELECT `id` FROM users WHERE `banned` = '0'") or
die (mysql_error());
list($id) = mysql_fetch_row($result);
if(empty($abstract))
{
$err[] = "ERROR - Enter Abstract";
//header("Location: thesis.php?msg=$err[0]");
}
/// Automatically collects the hostname or domain like example.com)
$host = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
if(empty($err)) {
for($i = 0; $i < count($_POST["other"]); $i++)
{
$thesis_Name = mysql_real_escape_string($_POST['thesis_Name'][$i]);
$abstract = mysql_real_escape_string($_POST['abstract'][$i]);
$sql_insert = "INSERT into `thesis`
(`user_id`,`thesis_Name`,`abstract` )
VALUES
('$id','$thesis_Name','$abstract' ";
mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
}
header("location: myaccount.php?id=" . $_SESSION['user_id']. "");
}
显然,当数据在框中时,第二个标题是它应该去的地方。如果我包含第一个标题,则错误消息在 URL 栏中,当我不包含标题行时,它在页面上(应该在哪里)帮助!
我的意思是当我收到错误时,这是我设置的错误,“输入摘要”一直显示,即使输入了某些内容。