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

时间:2014-10-09 11:35:41

标签: 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.php:

    <?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");


?>

任何帮助都会受到高度赞赏。谢谢。

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

    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;
....

}

答案 2 :(得分:0)

使用target =&#34; _blank&#34;这样它就会在新窗口中打开

<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

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

希望这对您有所帮助,对此问题发表评论。