Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在网页中检索用户注册详细信息?_Php_Html_Mysql_Css - Fatal编程技术网

Php 如何在网页中检索用户注册详细信息?

Php 如何在网页中检索用户注册详细信息?,php,html,mysql,css,Php,Html,Mysql,Css,我是PHP编程新手。我创建了注册页面和登录页面。当用户使用用户名和密码登录时,我想显示用户注册详细信息。我想知道如何将用户注册详细信息检索到网页中 我使用此代码注册和登录 注册码: <html> <title>Register Page</title> <script type="text/javascript"> function validateForm() { var a=document.f.name.value; var b=docum

我是PHP编程新手。我创建了注册页面和登录页面。当用户使用用户名和密码登录时,我想显示用户注册详细信息。我想知道如何将用户注册详细信息检索到网页中

我使用此代码注册和登录

注册码:

 <html>
<title>Register Page</title>
<script type="text/javascript">
function validateForm()
{
var a=document.f.name.value;
var b=document.f.pass.value;
var c=document.f.email.value;
var d=document.f.mobile.value;
 var e=document.f.sex.value;

if ((a==null || a=="") && (b==null || b=="") && (c==null || c=="") &&       
    (d==null ||    d==""))
   {
alert("All Field must be filled out");
return false;
}
if (a==null || a=="")
{
alert("Username must be filled out");
return false;
}
if (b==null || b=="")
{
alert("password must be filled out");
return false;
}
if (c==null || c=="")
{
alert("Email must be filled out");
return false;
}
if (d==null || d=="")
{
 alert("Enter the mobile number");
return false;
}
if(e=="Select")
{
alert("Please choose gender");
return false;
}



}
 </script>
 <style>
 #abc
 {
 background-color:#FF3366;
 }
 </style>
 <body bgcolor="#0099CC">
 <h1 id="abc"><center>Welcome to the register page</center></h1>
 <form name="f" action="regdb.php" method="post" onSubmit="return validateForm()">
 <table align="center">
 <tr><td>Fullname :&nbsp;<br><br></td><td><input type="text" name="name" id="name">
 <br><br></td></tr>

 <tr><td>Password :&nbsp;<br><br></td><td><input type="password" name="pass" id="pass">
 <br><br></td></tr> 
 <tr><td>Email    :&nbsp;<br><br></td><td><input type="text" name="email" id="email">
 <br><br></td></tr> 
 <tr><td>Mobile No:&nbsp;<br><br></td><td><input type="text" name="mobile" id="mobile">
 <br><br></td></tr>

 <tr><td>Gender      :&nbsp;<br><br></td><td><select name="sex"><option>Select</option>
                                     <option>Male</option>
                                     <option>Female</option></select><br><br></td></tr>
 <tr><td></td><td><input type="submit" 
  value="register"></td></tr>                                              
 </table>
</form>
</body>
</html>
注册数据库代码:

 <?php
$con=mysql_connect("localhost","root","");
if(!$con)
{
die("could not connect:".mysql_error());
}
 mysql_select_db("manoj",$con);

if (isset($_POST['name']) && isset($_POST['pass']) && isset($_POST['email']) && 
isset($_POST['mobile']) && isset($_POST['sex']))
{ 
//Prevent SQL injections 
$username = mysql_real_escape_string($_POST['name']); 
$email = mysql_real_escape_string($_POST['email']); 
$mobile = mysql_real_escape_string($_POST['mobile']);
$sex = mysql_real_escape_string($_POST['sex']); 

//Get MD5 hash of password 
 $password = $_POST['pass'];
//Check to see if username exists 
$sql = mysql_query("SELECT name FROM register WHERE name = '".$username."'");
if (mysql_num_rows($sql)>0) 
{ 
echo "The username you have entered is already exist. Please try another username.";
echo '<a href="reg.php">Try Again</a>';
exit;
} 
mysql_query("INSERT INTO register (name, password, email,mobile,sex) VALUES (    
'$username', '$password', '$email','$mobile','$sex')");
 echo "Thank You for Registration.";
echo '<a href="login.php">Click Here</a> to login you account.';
exit;
} 
?>
登录代码:

<html>
<head>
<title>Php Simple Login Form</title>

</head>
<script type="text/javascript">
function validateForm()
{
var a=document.f.username.value;
var b=document.f.password.value;

if ((a==null || a=="") && (b==null || b==""))
{
alert("All Field must be filled out");
return false;
}
if (a==null || a=="")
{
alert("Username must be filled out");
return false;
}
if (b==null || b=="")
{
alert("password must be filled out");
return false;
}

}
</script>
<style>
#abc
{
    background-color: #EFFBEF;
     text-decoration: blink;
  }
 #def
 {
    background-color:#00BFFF;

 } 

</style>

<body bgcolor="#00BFFF">
<div id="containt" align="center">
<form name="f" action="logindb.php" method="post" onSubmit="return validateForm()">
<center><h1 id="abc">Welcome To My Page </h1></center>
<div id="header"><h2 class="sansserif"> Login Here</h2></div>
<table>

    <tr>
        <td>Enter Username:</td>
        <td> <input type="text" name="username" size="20"></td>
    </tr>

    <tr>
        <td>Enter Password:</td>
        <td><input type="password" name="password" size="20"></td>
    </tr>
    <tr>
        <td></td>
         <td><input type="submit" value="Log In"></td>

    </tr>
</table>
<b>Don't have an account,please click here&nbsp;<a href="reg.php">Sign Up</a>  
 </b><br><br> 
 </form>
</div>
</body>
</html>
对于登录数据库代码:

<?php

session_start();

$con=mysql_connect("localhost","root","");
if(!$con)
{
die("could not connect:".mysql_error());
}


 mysql_select_db("manoj",$con);


$username = $_POST["username"]; 
$password = $_POST["password"]; 

$match = "select id from register where name = '".$_POST['username']."' and password = 
 '".$_POST['password']."'";
$qry = mysql_query($match);

$num_rows = mysql_num_rows($qry);

if ($num_rows<=0 ) 
{ 
echo "Incorrect username/password"; 
header('Location: login.php');
}
else 
{ 
//have them logged in 
$_SESSION['user']= $_POST["username"];
header('Location: profile.php');
} 

?>
在这里,我试图显示用户配置文件details-profile.php:

 <?php
session_start();
echo "You are Welcome ". $_SESSION['user'];
$con=mysql_connect("localhost","root","");
if(!$con)
{
die("could not connect:".mysql_error());
}
mysql_select_db("manoj",$con);

$sql="select * from register where name = '".$_SESSION['user']."'";
$res=mysql_query($sql);
echo "<table border='0'>";
while($r=mysql_fetch_array($res))
echo"<tr>"."<td>"."Name :"."</td>"."<td>".$r['name']."</td>"."</tr>";
 echo"<tr>"."<td>"."Password :"."</td>"."<td>".$r['password']."</td>"."</tr>";
echo"<tr>"."<td>"."Email :"."</td>"."<td>".$r['email']."</td>"."</tr>";
echo"<tr>"."<td>"."Mobile Number :"."</td>"."<td>".$r['mobile']."</td>"."</tr>";
echo"<tr>"."<td>"."Gender :"."</td>"."<td>".$r['sex']."</td>"."</tr>";
echo "</table>";
echo"<p align='right'><a href='logout.php'>Logout</a></p>";
mysql_close($con);
?>      
我正在使用此代码检索登录用户详细信息,但无法显示详细信息,它仅显示用户名。请帮助我。

您缺少while循环的{}分隔符

应该是这样的:

加上,使用MySql*函数被禁止,应该考虑使用MyQuiLy*或PDO。

您缺少while循环的{}分隔符。

应该是这样的:


加上,使用MySQL函数*,你应该考虑使用MyQuiLy*或PDO。< / P>请告诉我,你在实际代码中使用缩进?!?!?请阅读本教程。请告诉我您在实际代码中使用缩进!?!?请在+1上阅读本教程。应该像我一样添加mysql_fetch_assoc。。。这将是他犯下的下一个错误gets@Orangepill根据php.net mysql_fetch_array,$res与默认为mysql_的第二个变量一起工作,这两个变量都将给出assoc和num。感谢您的澄清。。。我已经删除了我的答案,因为它是不正确的。@manoj如果你想让用户能够修改他们的详细信息,你可以显示一个类似于注册表的表单,其中填充了来自MySQL的数据,然后在提交此表单时进行更新查询以更改表内容。+1很好。应该像我一样添加mysql_fetch_assoc。。。这将是他犯下的下一个错误gets@Orangepill根据php.net mysql_fetch_array,$res与默认为mysql_的第二个变量一起工作,这两个变量都将给出assoc和num。感谢您的澄清。。。我已经删除了我的答案,因为它是不正确的。@manoj如果你想让用户能够修改他们的详细信息,你可以显示一个类似于注册表的表单,其中填充了来自MySQL的数据,然后在提交此表单时进行更新查询以更改表内容。

echo "<table border='0'>";
while($r = mysql_fetch_array($res))
{
    // echo what you need
}
echo "</table>";