如果字段未完成,我在显示错误消息时遇到严重问题。 我希望错误消息显示何时抽象是空的,但如果填写,我希望提交按钮转到他们的帐户页面(在会话中) PHP:
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();
if(empty($_SESSION['$user_id'])) // user not logged in; redirect to somewhere else
if (!empty($_POST['doThesis']) && $_POST['doThesis'] == 'Save')
{
list($id) = mysql_fetch_row($result);
/// 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)) {
$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());
}
else{
header("location: myaccount.php?id=" . $_SESSION['user_id']. "");
exit();
}
}
}
在HTML中:
<script>
$(document).ready(function(){
$.validator.addMethod("abstract", function(value, element) {
return this.optional(element) || /^[a-z0-9\_]+$/i.test(value);
}, "Thesis.");
$("#regForm").validate();
});
</script>
<?php
if(!empty($err)) {
echo "<div class=\"msg\">";
foreach ($err as $e) {
echo "* $e <br>";
}
echo "</div>";
}
?>
如果您需要更多信息,请告诉我,因为我需要这项工作!