gpt4 book ai didi

php - 登录时出现空白页

转载 作者:行者123 更新时间:2023-11-30 00:45:53 26 4
gpt4 key购买 nike

我有用于登录我的网站的代码但是当我使用用户名和密码登录时,我得到空白页面我正在使用Linux服务器-fedora-我正在创建数据库并从终端导入表

这是我的页面表单

<html>
<head>
<body background="se16.jpg">
<form method="post" action="w.php">
<center>
<br>
<h1> <p style="color:brown;"> Login Page </p> </h1>

<hr color="brown"> <br>
<caption><h1><p style="color:black;">please Enter Username & Password</p></h1><caption>
<table border="3">

<tr><td><h2><p style="color:black;">Username: </p></td><td><input type="text" name="username" /></td><h2></tr>

<tr><td><h2><p style="color:black;">Password:</p> </td><td><input type="password" name="password" /></td></h2></tr>


<tr><td></td><td><input type="submit" value="Log in" /></td></tr>

</table>
</center>
</form>
</body>
</html>

查询的php页面是

<?php
session_start();
echo "username: " . $_POST['username'];
echo "<br>";
echo "Password: " . $_POST['password'];
echo "<br>";
include("connect.php");

// Pass Query
$query="SELECT username AND password FROM login ";

// Execute Query
$result = mysql_query($query) or die ("error in query:$query.".mysql_query());
echo $result;
echo "<br>";
$username=$_POST['username'];
$password=$_POST['password'];

if(mysql_num_rows($result)>0)
{
echo "ssss";
while($row=mysql_fetch_assoc($result))
{
$sql="SELECT * FROM login WHERE username='$username' AND password='$password'";
$result=mysql_query($sql) or die ("error in query:$query.".mysql_query());
$count=mysql_num_rows($result);

if($count == 1)
{
$query1="SELECT username FROM login WHERE password='$password'";
$result = mysql_query($query1)or die ("error in query:$query.".mysql_query());
while($row=mysql_fetch_assoc($result))
{
$username=$row['username'];
}
$flag=true;
break;
}
}
}
else
{
echo 'No Data Found';
}

if($flag==true)
{
$data = mysql_fetch_object(mysql_query("SELECT * FROM login WHERE username='$username' AND password='$password'"));
$_SESSION['valid_user'] = $data->id;
echo '<div align="left"><font color="#6666CC"> Welcome </font><font color="#FF6600">'.$username.'</font></div>';
echo '<div align="right"><a href="logout.php">Log Out</a></div>';
include("main1.php");
}
else
{
include("log1.html");
}

// mysql_close($con);
?>

如果我使用这个代码

     echo "username: " . $_POST['username'];
echo "<br>";
echo "Password: " . $_POST['password'];
echo "<br>";

我得到正确的用户名和密码

并连接.php文件

<?php
$host ="localhost";
$username ="root";
$password ="MyS12345";
$db_name ="jointdb";
$conn = mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

?>

最佳答案

首先查询不正确

$query="SELECT username AND password FROM login ";

应该是这样

$query="SELECT username,password FROM login ";

在connect.php中正确的代码是

$host ="localhost"; 
$username ="root";
$password ="MyS12345";
$db_name ="jointdb";
$conn = mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");

注意:mysql_* 函数已弃用,因此请开始学习 mysqli_* 函数或 PDO。

关于php - 登录时出现空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21360989/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com