【问题标题】:how to see users profile by searching him and by clicking on its link如何通过搜索用户并单击其链接来查看用户个人资料
【发布时间】:2018-03-08 08:14:00
【问题描述】:

我在这里创建了客户的链接。

<a name="id" href="https://127.0.0.1/new taxicab/account/driver/profile/index.php?id=<?php echo $data['id']; ?>"><?php echo $data['fullname']; ?></a>

index.php 是

    <?php $connection = new mysqli("localhost", "root", "black9024!@","new_taxicab");
$id = ($_GET['id']);
if (empty($_GET['id'])){
    header("location:cheat.php");
    die();
    $sql = "select * from driver where id = '$id'";
    $result = $db->sql_query($sql) or die (mysqli_error($sql));
    while($rws = mysqli_fetch_array($result)){}
    echo $rws['fullname'];?>
    <?php echo $rws['fullname'];

  }
?>

但它不能工作我知道它错了但是写的是什么请给我一些建议。

【问题讨论】:

  • 你的id字段是string吗?
  • 没有我上面的 html id 是一个字符串,它直接来自数据库
  • 如果是这样,那么在你的 inde.php 文件中你应该有id = $id(查询),并且你没有指定当前代码有什么问题

标签: php html mysql profile


【解决方案1】:

在您的 while 循环中, echo $rws['fullname'] 位于 while 的大括号之外。试试:

<?php

$connection = new mysqli("localhost", "root", "black9024!@","new_taxicab");

$id = ($_GET['id']);

if (empty($_GET['id'])){

 header("location:cheat.php");
die();
}

$sql = "select * from driver where id = '$id'";
$result = $db->sql_query($sql) or die (mysqli_error($sql));

while($rws = mysqli_fetch_array($result)){

echo $rws['fullname'];   <-- Here

};

?>

【讨论】:

  • 我会在 index.php 页面上测试一些东西。 id 变量是否从 $_GET 中填充?查询后是否填充了 $result。试试 print_r($result) 看看有没有什么收获。
【解决方案2】:
<?php

    $connection = new mysqli("localhost", "root", "black9024!@","new_taxicab");

    if (empty($_GET['id'])){

         header("location:cheat.php");
         die();
    }

    $sql = "select * from driver where id = '$_GET[‘id’]'";
    $result = $db->sql_query($sql) or die (mysqli_error($sql));

    while($rws = mysqli_fetch_array($result)){

        echo $rws;

    };

 ?>

可能需要更改我从手机输入的单引号

@joseph_J 你的回答看起来可以,但你需要自己回显 $rws 吗?

据我所知,您没有将数据作为包含项目 ID 和全名的数组返回?$data[‘id’] 这是从哪里来的?

【讨论】:

    猜你喜欢
    • 2015-03-31
    • 1970-01-01
    • 1970-01-01
    • 2022-12-16
    • 2014-10-09
    • 1970-01-01
    • 2012-01-20
    • 1970-01-01
    • 2015-01-03
    相关资源
    最近更新 更多