如何在两个php页面之间传递数据?

时间:2015-11-15 03:28:19

标签: php web

下面是我的fetch.php

<?php

//header("content-type:image/jpeg");

$host = 'localhost';
$user = 'root';
$pass = '';


$conn = mysql_connect($host, $user, $pass) or die("couldn't open the database");


$db = mysql_select_db("dummy",$conn);
$q="select * from car";

$result=mysql_query("$q",$conn);



//if (mysql_num_rows("$result") > 0) {
    // output data of each row
    while($row = mysql_fetch_array($result)) {
        //echo ""<img src='image/jpeg'.$row['avatar'] .""/>;





        echo "<img src=image.php?avatar=".$row['name']."width =300 height=300/>";
        //echo '<img src="image.php?ava='.$row['name'].'">';

        //header("content-type:image/jpeg");
        echo "<p>".$row['name']."</p>"; 

    }
//}



?>

以下是image.php

  <?php


header("content-type:image/jpeg");

$host = 'localhost';
$user = 'root';
$pass = '';


$conn = mysql_connect($host, $user, $pass) or die("couldn't open the database");


$db = mysql_select_db("dummy",$conn);


$ava = $_GET['avatar'];
//$ava ="audi";
//session_set();
//$_SESSION['name'] = $_GET['name'];
$q = "select avatar from car where name ='$ava'";


$r = mysql_query("$q",$conn);

if($r){

    $row = mysql_fetch_array($r);


    echo $row['avatar'];
}

?>

当我试图通过&#39; name&#39;从fetch.php到image.php的数据,并根据名称尝试图像,我无法得到它?

有人可以在我出错的地方帮助我吗?

1 个答案:

答案 0 :(得分:1)

您将avatar=".$row['avatar']添加到网址但检查

$ava = $_GET['ava'];

avatar!= ava