【问题标题】:Why won't my img show?为什么我的img不显示?
【发布时间】:2012-11-27 15:28:41
【问题描述】:

让这一切都与 html 一起工作。然后我试着把它做成 html5 并且我正在编写我的第一个 css 代码。我现在唯一要解决的是为什么我的图像没有显示?我正在使用谷歌浏览器顺便说一句。 url 中传递的代码是这样的:"?fname=raichu&yesorno=true%2F" 而且我生成的 html 中没有图像标签:/ 我假设 if 语句等于 false??

<!DOCTYPE HTML>
<html>
<head>

<style type="text/css"> 

 td{
    text-align: center;
    padding:15px;
    background-color:black;
    color:#00FF00;}

 th{
    background-color:black;
    color:yellow}

</style>

         <title>Search Results</title>

</head>

    <body style="color:#FFFFFF"> 

<?php

$dbhost = 'server';
$dbname = 'database1';
$dbuser = 'me';
$dbpass = 'password';

$link = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);

mysqli_select_db($link,$dbname);

$naame = $_GET["fname"];


if( $_GET["yesorno"] == 'true' OR !$_GET["yesorno"])
            {$query = sprintf("SELECT image_url, Type 
                               FROM Pokemon c 
                               WHERE c.name='%s'", mysqli_real_escape_string($link,$naame));

    $result = mysqli_fetch_assoc(mysqli_query($link,$query));

    echo '<img height="450" width="330" src="'.$result['image_url'].'" alt="blue"/>';}

$res = mysqli_query($link,"SELECT Name,HP,Type,Pokedex_Number AS 'Pokedex  Number',Weakness,Resistance,Retreat AS 'Retreat Cost' 
                           FROM Pokemon 
                           WHERE Pokedex_Number!=0 AND name='$naame'");

if (!$res) {
    die("Query to show fields from table failed");}

    $fields_num = mysqli_num_fields($res);

echo "<h1>Stats</h1>";
echo "<table border='1'><tr>";

// printing table headers
for($i=0; $i<$fields_num; $i++)
{$field = mysqli_fetch_field($res);
echo "<th>{$field->name}</th>";}

echo "</tr>\n";

// printing table rows
while($row = mysqli_fetch_row($res))
{
echo "<tr>";

// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
    echo "<td>$cell</td>";

echo "</tr>\n";
}   

echo "</table>";

mysqli_close($link);

    ?>

<br />
<form method="link" 
action = "http://engr.oregonstate.edu/~bainro/welcome.php" ><input 
type="submit" value="(>O.O)>RETURN<(O.O<)"></form>
<p></p>

    </body>

</html>

【问题讨论】:

  • 你能粘贴 image_url 的值吗?
  • 你确定你传递的地址是正确的
  • 如何发布生成的html?
  • 右键单击网页内的任意位置,然后单击查看源代码。找到&lt;img ...&gt; 标记并将该部分复制粘贴到您的问题中。或者,如果不是太长,您可以复制粘贴整个生成的 html。

标签: php sql css html


【解决方案1】:

你有

&yesorno=true%2F

因此 $_GET['yesorno'] 将等同于 'true/',因为 %2f 是一个正斜杠。

这不匹配

if( $_GET["yesorno"] == 'true' OR !$_GET["yesorno"])

所以你是对的 - 那条线是失败的,所以你不会得到图像。

解决方案:从查询中删除 %2F。

【讨论】:

    【解决方案2】:

    您从 url 检索的变量永远不会评估为 true,因为 '%2F' 是正斜杠。检查您的代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-17
      • 2012-09-08
      • 2016-11-12
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多