表单各项一定要加name属性,POST 和GET 取值都是通过name属性传参数获取的。不设置NAME属性获取不到值。
HTML JS PHP MYSQL 字符集 最好统一。
HTML JS PHP HTTP 请求方式必须统一。
举例:
html代码:
<form id="reg_form" method="post" action="reg_submit.php" οnsubmit="return check_form(this)" name="reg_form">
<input type="text" id="username_input" name="username_input"οnblur="check_username()" οnkeyup="check_username()"/>
<input type="text" id="email_input" name="email_input"οnblur="check_email()" οnkeyup="check_email()"/>
<input type="password" id="password_input" name="password_input" οnblur="check_password()" οnkeyup="check_password()" />
<input type="password" id="repassword_input" name="repassword_input"οnblur="check_repassword()" οnkeyup="check_repassword()" />
<input type="text" id="name_input" name="name_input" />
<input type="submit" id="tijiao" value="" name="tijao"/>
<input type="button" id="quxiao" value="" name="quxiao"/>
<input type="hidden" id="username_check" value="0"/>
<input type="hidden" id="email_check"/ value="0">
</form>
PHP代码:
<?php
header("Content-type: text/html; charset=UTF-8");
error_reporting(0);
$username_value = $_POST['username_input'];
$email_value = $_POST['email_input'];
$password_value=$_GET['password_input'];
$name_value=$_POST['name_input'];
include('data/conn.php');
//$regdate = time();
$sql = "INSERT INTO t_user(f_username,f_email,f_password,f_name)VALUES('$username_value','$email_value','$password_value','$name_value')";
if(mysql_query($sql,$conn)){
echo $username_value;
//echo $sql; 打印执行时的SQL语句
//echo $password_value;//打印传递的密码值
exit('用户恭喜注册成功!点击此处 <a href="login.html">登录</a>');
} else {
echo '抱歉!添加数据失败:',mysql_error(),'<br />';
echo '点击此处 <a href="javascript:history.back(-1);">返回</a> 重试';
}
?>
转载于:https://blog.51cto.com/zhengshuheng/1585743