的index.php
<?php
// set error reporting level
if (version_compare(phpversion(), '5.3.0', '>=') == 1)
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
else
error_reporting(E_ALL & ~E_NOTICE);
session_start();
if (isset($_POST['submit']))
{
if (strlen($sEmail) >= 1 and strlen($sEmail) <= 55) {
if (ereg('^[a-zA-Z0-9\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $sEmail)) {
// Here you can add him to database
$con=mysqli_connect("localhost","root","mypuppy29","test");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$EMAIL = mysqli_real_escape_string($con, $_POST['email']);
$sql="INSERT INTO subscribers VALUES (DEFAULT, '$EMAIL')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
}
}
else {
$sErrors = 'Email is wrong';
}
}
// display step 2
$aParams = array(
'{email}' => $sEmail,
);
main_html.page
<!DOCTYPE html>
<html lang="en" >
<head>
<title>Form Validation with Javascript and PHP</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="main.css" type="text/css">
<link rel="stylesheet" href="main.css" type="text/css"/>
<script src="js/script.js"></script>
</head>
<body>
<header>
<h2>Form Validation with Javascript and PHP</h2>
</header>
<div class="container">
<form action="index.php" method="post" id="form" onsubmit="return
<table cellspacing="10">
<tr><td>Email</td><td><input type="text" name="email" maxlength="50"
validate_all('results');">
id="email" ><br /><div id="email_length"></div></td></tr>
<tr><td> colspan="2"><input type="submit" name="submit" value="Register">
</tr></td></table>
<h3 id="results"></h3>
</form>
</div>
</body>
</html>
的script.js
function check_v_mail(field) {
fld_value = document.getElementById(field).value;
is_m_valid = 0;
if (fld_value.indexOf('@') >= 1) {
m_valid_dom = fld_value.substr(fld_value.indexOf('@')+1);
if (m_valid_dom.indexOf('@') == -1) {
if (m_valid_dom.indexOf('.') >= 1) {
m_valid_dom_e = m_valid_dom.substr(m_valid_dom.indexOf('.')+1);
if (m_valid_dom_e.length >= 1) {
is_m_valid = 1;
}
}
}
}
if (is_m_valid) {
update_css_class(field, 2);
m_valid_r = 1;
} else {
update_css_class(field, 1);
m_valid_r = 0;
}
return m_valid_r;
}
function validate_all(output) {
t4 = check_v_mail('email');
errorlist = '';
}
if (! t4) {
errorlist += 'Mail is wrong<br />';
}
我正在尝试验证地址并将其发送到mysql数据库php是非常新的并且接受了一些但仍然无法做到的在线帮助我正在获取页面但是重定向php页面不工作我也尝试过用另一种方式
<?php
include("include.php");
//Creating a form block
if(!$_POST)
{
$display_block = "
<form method = \"POST\" action =\"".$_SERVER["PHP_SELF"]."\">
Email: <input type = \"text\" name = \"email\">
Submit: <input type = \"submit\" name = \"submit\">
</form>";
} else if(($_POST)&&($_POST["action"]=="sub"))
{
//trying to subscribe;validate email address
if($_POST["email"]== "")
{
header("Location:manage.php");
exit;
}
else
{
//connect to database
doDB();
//check the email is in list
emailChecker($_POST("email"));
//get number of results and do the action
if (mysqli_num_rows($check_res)<1)
{
//free results
mysqli_free_result($check_res);
//add record
$add_sql = "INSERT INTO subscribers(email)
VALUES('".$_POST["email"]."')";
$add_res = mysqli_query($mysqli,$addsql)
or die (mysqli_error($mysqli));
$display_block = "<p>Thanks for signing up!</p>";
//close connection to mysql
mysqli_close($mysqli);
}
else{
//print faliure message
$display_block = "<p>You are already subscribed!</p>";
}
}
}
?>
<html>
<head></head>
<body>
<?php echo "$display_block";?>
</body>
</html>
此代码无效并显示以下错误。我有一个包含psd格式的HTML和CSS文件,并且需要这种类型的功能。我正在尝试使用示例HTML的功能,但我无法。有人可以帮帮我吗?
注意:未定义的索引:第15行的C:\ Apache24 \ htdocs \ manage.php中的操作
注意:未定义的变量:第64行的C:\ Apache24 \ htdocs \ manage.php中的display_block