0

我有三个php页面,第一页是在字段中输入用户详细信息第二页是在数据库中插入用户详细信息第三页是显示已发送到数据库的用户详细信息,

一切正常,除了在第三页没有出现用户详细信息并且我收到以下错误消息:

注意:未定义变量:user 注意:未定义变量:email 注意:未定义变量:pass

这是我的代码:

first_page.php

<form action="second_page.php" method="post" >
User Name:  
<input  type="text" name="username" >
User Email
<input  type="text" name="useremail" >
Password:  
<input  type="text" name="password" >
<input type="submit"  name="submit" >
</form>

second_page.php

if (isset($_POST['submit'])) 
{
$user= $_POST['username'];
$email = $_POST['useremail'];
$pass= $_POST['password']; 

mysql_query("INSERT INTO table (username, useremail, password) VALUES  ('$user','$emai','$pass');
header("location: third_page.php");
exit;

第三页.php

$user= $_POST['username'];
$email = $_POST['useremail'];
$pass= $_POST['password']; 

echo ' the user name: '.$user;
echo ' the user email:.'$email;
echo 'the user password:.'$pass;
4

5 回答 5

1
$user_id = mysql_insert_id();
header("location: third_page.php?id=$user_id");

anf ftech data from datbase
于 2013-08-08T10:58:41.337 回答
0

您只是在其中进行了一些分配,third_page.php但没有将实际输入发送到该页面。如果您希望能够访问该页面中的变量,您将查询数据库并直接获取结果,或者使用会话。

方法一:

second_page.php中,添加以下内容:

$_SESSION['username'] = $user;
$_SESSION['useremail'] = $email;
$_SESSION['password'] = $pass;

third_page.php中,添加以下内容:

$user = $_SESSION['username'];
$email = $_SESSION['useremail'];
$pass = $_SESSION['password'];

现在您将能够访问third_page.php.

方法二:

$query = mysql_query("SELECT username, useremail, password FROM table") or die (mysql_error());

while ($row = mysql_fetch_array($query)) {
    $user = $row['username'];
    $email = $row['useremail'];
    $pass = $row['password'];
}

重要的:

希望这可以帮助!

于 2013-08-08T10:55:04.010 回答
0

在 third_page.php 中,您的$_POST数据是空的(您没有在 中发送表单second_page.php)。

尝试从您的数据库中获取数据third_page.php

还有一件事, in second_page.php$username没有$useremail定义(你定义了$userand $pass)。

于 2013-08-08T10:55:39.070 回答
0

替换以下代码:

mysql_query("INSERT INTO table (username, useremail, email) VALUES  ('$username','$useremail','$email');
header("location: third_page.php");

使用以下代码:

mysql_query("INSERT INTO table (username, useremail, email) VALUES  ('$user','$email','$email');
header("location: third_page.php?username=$user&useremail=$email&password=$pass");

并且还使用 $_REQUEST 更改 $_POST:

$user= $_REQUEST['username'];
$email = $_REQUEST['useremail'];
$pass= $_REQUEST['password'];

但是通过 URL 发送数据并不安全,因此在 url 中发送 id 并在third.php页面上获取数据是一种很好的做法。

于 2013-08-08T10:59:16.447 回答
0

这是我的代码,查询数据库然后打印结果

<?php
$con=mysqli_connect("localhost","name","pass","db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * your where statement");
$job = array();
while($row = mysqli_fetch_array($result)){
    $job[] = $row;
}



<div id="content">
        <div class="priority">
        <?php foreach($job as $item): ?>
            <div class="jobpost">

            Job: <?php echo $item['job'] ?><br />
            Type: <?php echo $item['type'] ?><br />
            Comments: <?php echo $item['comments'] ?><br />
            Timescale: <?php echo $item['timescale'] ?><br />
            Date: <?php echo $item['date'] ?><br />
            <a href="<?php echo $item['id'] ?>">Go to this job</a>


        </div>
        <?php endforeach; ?>
    </div>
于 2013-08-08T11:02:43.990 回答