我有一个问题,一个登录,页面没有显示任何东西。这是代码:
PHP:
<?php
require 'connect_db.php';
/* start the session */
session_start();
conectar();
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "SELECT * FROM teachers WHERE email='$email' and password='$password'";
$result = mysql_query($sql);
// counting table row
$count = mysql_num_rows($result);
if($count == 1)
{
$_SESSION['loggedin'] = true;
$_SESSION['email'] = $email;
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (10 * 60) ;
echo "<body><p>Welcome! </p></body>";
}
else
{
echo "Mail or password not correct.";
echo "<a href='teacher.html'>Try again</a>";
}
//$conexion->close();
?>调用此代码的是:
<form action= "php/login_profesores.php" method="POST" onsubmit="return validacion()">
<label>Mail</label>
<input type="text" class="" id="inputMail"></input></br></br>
<label>DNI</label>
<input type="password" id="inputDNI"></input></br>
<input name="Enviar" type="submit" class="submit" value="Send" /></input></br>
</form>validación()是javascript代码,但问题是当用户在系统中登录时,php‘’不会显示任何页面。数据库配置良好,并且存在教师的表。
connect_db
<?php
function conectar()
{
define('DB_SERVER','http://**/');
define('DB_NAME','**');
define('DB_USER','**');
define('DB_PASS','**');
$conexion=new mysqli();
$conexion->connect('DB_SERVER','DB_USER','DB_PASS', 'DB_NAME');
$error=$conexion->connect_error; //Tambien vale connect_error
echo $error;
}
?>发布于 2016-05-07 09:00:03
如果要使用POST、GET或任何其他方法传递值,则必须在输入字段中具有name属性。
<input type="text" class="" name="email" id="inputMail"></input></br></br>
<label>DNI</label>
<input type="password" name="password" id="inputDNI"></input></br>发布于 2016-05-07 09:00:31
在表单中,您指定了输入类型,但没有为此指定名称。
发布于 2016-05-07 09:05:17
您在PHP页面中使用MySQL_过程,但在连接页中使用面向MySQLi_对象。
将所有内容更新为MySQLi (面向对象的)。现在不再支持MySQL_,不应该使用它。
您还应该使用SQL检查它是否允许从您的页面试图访问的IP地址访问它。如果它们位于同一台服务器上,那么您应该用localhost替换您的SQL数据库连接地址。
https://stackoverflow.com/questions/37086455
复制相似问题