<input autocomplete="off" spellcheck="false" type="text" placeholder="手机号" maxlength="11" class="ivu-input ivu-input-default ivu-input-with-prefix">
<input autocomplete="off" spellcheck="false" type="password" placeholder="密码" class="ivu-input ivu-input-default ivu-input-with-prefix">
这段代码中,手机号和密码的input没有v-bind、v-model、ref、id属性,我在登录login.php中$password = $_POST['password'];可以post获取到input中密码的值, $username = $_POST['text'];却post获取不到手机号输入框里面的数据,该怎么获取手机号input中的值和数据库中的值进行校验的?
按照大佬说的,加了name属性。
<input autocomplete="off" spellcheck="false" type="text" name="phone" placeholder="手机号" maxlength="11" class="ivu-input ivu-input-default ivu-input-with-prefix">
<input autocomplete="off" spellcheck="false" type="password" name="password" placeholder="密码" class="ivu-input ivu-input-default ivu-input-with-prefix">
在php里面post:
<?PHP
header("Content-Type: text/html; charset=utf-8");
include('conn.php');//链接数据库
ini_set("display_errors","On");
error_reporting(E_ALL);
$phone = isset($_POST['phone']) ? trim($_POST['phone']) : '';//post获得用户名表单值
$password = isset($_POST['password']) ? $_POST['password'] : '';//post获得用户密码单值
echo $phone;
echo $password;
if ($phone && $password){//如果用户名和密码都不为空
$sql = "select * from user where phone = '$phone' and password = '$password' ";//检测数据库是否有对应的phone和password的sql
$res = mysql_query($sql);//执行sql
$rows = mysql_num_rows($res);//返回一个数值
if($rows){//0 false 1 true
header("refresh:0;url=index.html");//如果成功跳转至index.html页面
exit;
}else{
echo "用户名或密码错误";
echo "
<script>
setTimeout(function(){window.location.href='login.html';},1000);
</script>";
//如果错误使用js 1秒后跳转到登录页面重试,让其从新进行输入
}
}else{//如果用户名或密码有空
echo "没有获取到手机号或者密码";
echo "
<script>
setTimeout(function(){window.location.href='login.html';},1000);
</script>";
//如果错误使用js 1秒后跳转到登录页面重试,让其从新进行输入
}
mysql_close();//关闭数据库
?>
报错:
Notice: Undefined index: phone in E:\ceshi\php\login.php on line 9
123456没有获取到手机号或者密码
123456是post的密码,还是post不到phone。
设置name属性,通过name属性获取看一下