如何在php的单独页面中显示数据库中的当前用户详细信息

时间:2014-10-09 04:46:44

标签: php

这是我的index.php:

<?php
    define('INCLUDE_CHECK',1);
    require "config.php";
    require "functions.php";
    require "data.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>

data.php:

<?php
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $conn )
    {
      die('Could not connect: ' . mysql_error());
    }
    $sql = 'SELECT fname, lname, email FROM crop';

    mysql_select_db('crop');
    $retval = mysql_query( $sql, $conn );

if($result){ $sql = "SELECT fname, lname, email FROM crop where id='$id'"; $retval = mysql_query( $sql); if(! $retval ) { die('Could not get data: ' . mysql_error()); } while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo "First Name :{$row['fname']} <br> ". "Last Name : {$row['lname']} <br> ". "Email Address : {$row['email']} <br> ". "--------------------------------<br>"; } }
       echo "Fetched data successfully\n";
    mysql_close($conn);
    ?>

我使用php和jquery创建了注册表单,并使用了一些函数。

现在我需要在注册后将当前用户详细信息显示在单独的页面中。

现在我得到了,没有显示任何内容,它只显示成功获取的数据。

请帮我解决这个问题。谢谢。

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

<?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')");
    if(mysql_affected_rows()>1)
        {

        //it will redeirect you to. your any file. 
        //you can give any file name here. 
           $_SESSION['fname']=$fname;//you are adding value to the session
         $_SESSION['lanme']=$lname; //you are adding value to the session
    //Do this for rest of your value
    header('Location:Your_File_name.php');
        }



    if (!$result) {
        die(msg(0,"wrong query"));
    }
        ?>