douhu2898 2014-04-04 15:44
浏览 114
已采纳

Mysql和PHP不会回显查询结果

<?php

mysql_connect("localhost", "root", "usbw");
mysql_select_db("europese unie");

$id = $_GET['Land'];
$query = "SELECT `Land`, `Oppervlakte`, `Inwoners`, `Klimaat`, `Motto`, `UTC` FROM `algemene informatie` WHERE `Land` = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
$land = $row[0];

echo "$land"; 



print("<h2>$id</h2>");
print("<br />");


die(mysql_error())

?>

when i tried to run this code i expected to echo the first land that came up with this query instead i got nothing. i am not a very experienced PHP or Mysql user nor is english my first language so pleas do not hold annything against me.

  • 写回答

3条回答 默认 最新

  • doujiaoang69440 2014-04-04 16:44
    关注

    Solved

    Taken from comments:

    "well the adress is localhost:8080/details.php?Land=%20Belgie and $id = $_GET['Land']; is the id so Belgie should be $id but as var_dump($result) it keeps giving bool(false)"

    • Basically what you're asking SQL, is to find (space)Belgie and since your column doesn't contain the word Belgie with a space, it will not find it; least that's what I think is happening

    That %20 is a space btw. That could be the problem. You could make use of the trim() function.

    Use:

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

    OP:

    thank you print_r($row); now gives Array ( [0] => Belgie [1] => 31 [2] => 11 [3] => gematigd zeeklimaat [4] => Eendracht maakt macht [5] => 1 ) i can finaly proceed


    Sidenote: Your present code is open to SQL injection. Use mysqli_* functions. (which I recommend you use and with prepared statements, or PDO)

    mysql_* functions are deprecated and will be removed from future PHP releases.


    Footnotes:

    mysql_* functions deprecation notice:

    http://www.php.net/manual/en/intro.mysql.php

    This extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used. See also the MySQL API Overview for further help while choosing a MySQL API.

    These functions allow you to access MySQL database servers. More information about MySQL can be found at » http://www.mysql.com/.

    Documentation for MySQL can be found at » http://dev.mysql.com/doc/.

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀