如何在php中的新窗口中显示当前用户的详细信息


How to display current user details in new window in php

我已经使用php-mqsql创建了注册表形式。

注册后,特定的用户详细信息需要从数据库中检索并显示在新窗口中。

这是我的下面:

index.php:

<?php
    define('INCLUDE_CHECK',1);
    require "config.php";
    require "functions.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Creating a Facebook-like Registration Form with jQuery</title>
<link rel="stylesheet" type="text/css" href="demo.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div id="div-regForm">
<div class="form-title">Sign Up</div>
<div class="form-sub-title">It's free and anyone can join</div>
<form id="regForm" action="submit.php" method="post">
<table>
  <tbody>
  <tr>
    <td><label for="fname">First Name:</label></td>
    <td><div class="input-container"><input name="fname" id="fname" type="text" /></div></td>
  </tr>
  <tr>
    <td><label for="lname">Last Name:</label></td>
    <td><div class="input-container"><input name="lname" id="lname" type="text" /></div></td>
  </tr>
  <tr>
    <td><label for="email">Your Email:</label></td>
    <td><div class="input-container"><input name="email" id="email" type="text" /></div></td>
  </tr>
 <tr>
  <tr>
    <td><label for="pass">New Password:</label></td>
    <td><div class="input-container"><input name="pass" id="pass" type="password" /></div></td>
  </tr>
 <tr>
    <td><label for="pass">Phone Number:</label></td>
    <td><div class="input-container"><input name="phone" id="phone" type="text" /></div></td>
  </tr>
    <td><label for="sex-select">I am:</label></td>
    <td>
    <div class="input-container">
    <select name="sex_select" id="sex-select">
    <option value="0">Select Sex:</option>
    <option value="1">Female</option>
    <option value="2">Male</option>
    </select>
    </div>   
    </td>
  </tr>
  <tr>
    <td><label>Birthday:</label></td>
    <td>
    <div class="input-container">
    <select name="month"><option value="0">Month:</option><?=generate_options(1,12)?></select>
    <select name="day"><option value="0">Day:</option><?=generate_options(1,31)?></select>
    <select name="year"><option value="0">Year:</option><?=generate_options(date('Y'),1900)?></select>
    </div>
    </td>
  </tr>
  <tr>
  <td>&nbsp;</td>
  <td><input type="submit" class="greenButton" value="Sign Up" /><img id="loading" src="img/ajax-loader.gif" alt="working.." />
</td>
  </tr> 
  </tbody>
</table>
</form>
<div id="error">
&nbsp;
</div>
</div>
</body>
</html>

code_exec.hp:

    <?php
       include 'config.php';
        error_reporting(E_ERROR);
        session_start();
        $fname=$_POST['fname'];
        $lname=$_POST['lname'];
        $email=$_POST['email'];
        $pass=$_POST['pass'];
        $phone=$_POST['phone'];
        $sex_select=$_POST['sex_select'];
        $month=$_POST['month'];
        $day=$_POST['day'];
        $year=$_POST['year'];
        $result = mysql_query("INSERT INTO crop(fname, lname, email, pass, phone,`sex_select`, month,day,year)  
VALUES ('$fname', '$lname', '$email', '$pass','$phone','$sex_select', '$month','$day','$year')");
printf("Last inserted record has id %d'n", mysql_insert_id()); // This will print the last insert id 
if (!$result) {
    die(msg(0,"wrong query"));
}
elseif(mysql_insert_id())
{
$_SESSION["fname"] = $fname;
$_SESSION["lname"] =  $lname;
    $email=$_POST['email'];
    $pass=$_POST['pass'];
    $phone=$_POST['phone'];
    $sex_select=$_POST['sex_select'];
    $month=$_POST['month'];
    $day=$_POST['day'];
    $year=$_POST['year'];
}
    ?>

这是submit.php:

<?php
// we check if everything is filled in
    require "config.php";
    require "functions.php";
if(empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['email']) || empty($_POST['pass']) || empty($_POST['sex_select']) || empty($_POST['phone']) || empty($_POST['month']) || empty($_POST['day']) || empty($_POST['year']))
{
    die(msg(0,"All the fields are required"));
}

// is the sex selected?
if(!(int)$_POST['sex_select'])
{
    die(msg(0,"You have to select your sex"));
}

// is the birthday selected?
if(!(int)$_POST['day'] || !(int)$_POST['month'] || !(int)$_POST['year'])
{
    die(msg(0,"You have to fill in your birthday"));
}

// is the email valid?
if(!(preg_match("/^['.A-z0-9_'-'+]+[@][A-z0-9_'-]+([.][A-z0-9_'-]+)+[A-z]{1,4}$/", $_POST['email'])))
    die(msg(0,"You haven't provided a valid email"));
// is the phone number valid?
if(!(preg_match("/([0-9]{10})|([0-9]{3}''s+[0-9]{3}''s+[0-9]{4})/", $_POST['phone'])))
die(msg(0,"You haven't provided a valid phone number"));
// Here you must put your code for validating and escaping all the input data,
// inserting new records in your DB and echo-ing a message of the type:
// echo msg(1,"/member-area.php");
include 'code_exec.php';
// where member-area.php is the address on your site where registered users are
// redirected after registration.
echo msg(1,"registered.html");

?>

如有任何帮助,我们将不胜感激。提前谢谢。

    include 'config.php';
    error_reporting(E_ERROR);
    session_start();
    $fname=$_POST['fname'];
    $lname=$_POST['lname'];
    $email=$_POST['email'];
    $pass=$_POST['pass'];
    $phone=$_POST['phone'];
    $sex_select=$_POST['sex_select'];
    $month=$_POST['month'];
    $day=$_POST['day'];
    $year=$_POST['year'];
    $result = mysql_query("INSERT INTO crop(fname, lname, email, pass, phone,`sex_select`, month,day,year) , VALUES ('$fname', '$lname', '$email', '$pass','$phone','$sex_select', '$month','$day','$year')");
printf("Last inserted record has id %d'n", mysql_insert_id()); // This will print the last insert id 
if (!$result) {
    die(msg(0,"wrong query"));
}
elseif(mysql_insert_id())
{
$_SESSION["fname"] = $fname;
$_SESSION["lname"] =  $lname;
....
}

我不知道你是在使用mysqli,还是mysql:-),但我如何理解你的问题?你可以使用"$yourdatabaseonnection->insert_id",这将返回用户使用的连接中插入到[UserDatabase]数据库中的最后一个"id"。然后用$_GET[]或会话将其发送到下一页:-)

使用target="_blank"以便在新窗口中打开

<form id="regForm" target="_blank" action="submit.php" method="post">

确保使用在每个页面中启动会话

if(!session_id())
     session_start();

然后在成功插入数据库后将用户详细信息保存在会话中(即)

$_SESSION['user_id']=""//some value;

然后您的submit.php重定向到另一个页面,比如user_details.php使用标头顺序重定向(例如)

header("location:user_details.php");  //make sure this is placed before your html codes in case using in some other page

然后使用您创建的会话来收集用户详细信息并在此页面中显示

希望这对你有所帮助,对任何有关这方面的问题发表评论。