dqbr37828
dqbr37828
2014-10-09 11:35

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

已采纳

I have created register form using php mqsql.

After registered that particular user details need to retrieve from database and show in new window.

This is my below:

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
", 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'];

}
    ?>

and this is 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");


?>

Any help would be highly appreciated.Thanks in advance.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • dpw43061 dpw43061 7年前
        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
    ", 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;
    ....
    
    }
    
    点赞 评论 复制链接分享
  • dongpu1879 dongpu1879 7年前

    use target="_blank" so that it opens in a new window

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

    make sure u start the session in each and every page using

    if(!session_id())
         session_start();
    

    then save users details in a session after the successful insertion in to the database (i.e)

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

    then redirect your submit.php to a nother page say user_details.php use the header inorder to redirect (e.g)

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

    then use your session created to gather user details and display them in this page

    hope this helps you, comment for any questions regarding this.

    点赞 评论 复制链接分享
  • doushun1904 doushun1904 7年前

    I dont know if you are using mysqli, or mysql :-) but how i understand your problem you can you "$yourdatabaseconnnection->insert_id", this will return the last "id", inserted in your [UserDatabase] database, from the connection the user uses. Then send that with a $_GET[], or an session to the next page :-)

    点赞 评论 复制链接分享

相关推荐