dongleiwei2182 2013-07-16 00:26
浏览 76
已采纳

返回查询结果

So, I'm writing this application in PHP where the user has a "Student's Name" and each user has a unique student name. So, before I go any further with my problem, here is the code *Note I've already prevented the SQL injections

    function hello($username123) {
       // Connect to Database //
$host3     = "db"; 
$username3 = "db"; 
$password3 = "db"; 
$db3       = "db";
$con3 = mysqli_connect($host3,$username3,$password3,$db3) or die("Can not connect to Server.");
$query3 = mysqli_query($con3,"SELECT student1 FROM users WHERE username = '$username123'");
$student1name = "$query3";
return $student1name;

So, the person enters the username which the registered before hand and each user has a student name.I start a query which selects student1 and student1 is equal to student1name. Student 1 name is then defnied as query3. When I test it all out, all I get is (null).. Does anyone know the problem? Thank you!

  • 写回答

2条回答 默认 最新

  • doulu8537 2013-07-16 01:13
    关注

    I suspect what you want is something like this:

    function hello($username123) {
        // Connect to Database //
        $host3     = "db"; 
        $username3 = "db"; 
        $password3 = "db"; 
        $db3       = "db";
        $con3 = mysqli_connect($host3,$username3,$password3,$db3) or die("Can not connect to Server.");
        $query3 = mysqli_query($con3,"SELECT student1 FROM users WHERE username = '$username123'");
        while ($row = mysqli_fetch_array($query3))
        {
            $student1name = $row['student1'];
        }
        return $student1name;
    

    This will put the contents of the last returned row of your query, column "student1", into the variable $student1name, and return it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?