Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法将数据从mysql检索到我的网页_Php_Html_Sql - Fatal编程技术网

Php 无法将数据从mysql检索到我的网页

Php 无法将数据从mysql检索到我的网页,php,html,sql,Php,Html,Sql,我想用php和mysql在我的网站上创建一个自动cms i、 我只需要将数据输入mysql表,它就会生成结果。 所以我的代码是: <!DOCTYPE html> <html> <head> <?php include 'head.php'; include 'conct.php'; ?> <title>GIZMOMANIACS|DOWNLOADS</title> </head

我想用php和mysql在我的网站上创建一个自动cms i、 我只需要将数据输入mysql表,它就会生成结果。 所以我的代码是:

<!DOCTYPE html> 
<html> 
<head> 
  <?php 
    include 'head.php';
     include 'conct.php';
   ?> 
  <title>GIZMOMANIACS|DOWNLOADS</title> 
</head>
<body> 
   <div id="container" style="width:100%;height:100%;clear:both">
   <div id="header" style="background-color:#FFFFFF;"> 
   <div class="head" style="clear:both">
   <a href= "http://gizmomaniacs.site88.net">
   <img src="/GM%203D.gif" width= "200" height="100" alt='gizmomaniacs logo'></a></div> 
   <h1 style="margin-bottom:0; float:right"><font id="gmfont">GIZMOMANIACS</font></h1>
 </div> 
    <div id="menu" style="clear:both;background-color:#0762AE">
    <?php  include 'head.html'; ?></div> <div class="content" >  
    <?php include 'search.php'; ?> 
<ul>
<?php
  $sql = "SELECT * from downloads";
  $result = mysql_query($sql);
  if($result==false){
        $view = "error";
        $error = "Could not retrieve values";
    }
   else {
        $dload = $GET_['downloadname'];
        $imagelink = $GET_['imagelink'];
        $title =  $GET_['title'];
        while ($row = mysql_fetch_array($result)) 
        {
           echo "<li><a class =\"alldld\" href=\"$dload\" title=\"$title\"><img  class=\"downloads\" src =\"$imagelink\"/>$title</a><br></li>";
        }
   }
?>
</ul>
    </div> 
    <div class="social"> 
<?php 
   include 'social.php'; 
?></div> 
</div> 
</body> 
</html>

GIZMOMANIACS |下载
小发明
一切都很好,但有三件事没有发生,它们是:

  • a href a属性未从数据库检索
  • 未从数据库检索的标题属性
  • img src属性未从数据库检索
  • 在显示的实际来源中

    <a class ="alldld" href="" title=""><img class="downloads" src =""/></a><br></li>  
    
    <li><a class ="alldld" href="" title=""><img class="downloads" src =""/></a>
    

  • src href title属性为空


    那么该怎么办呢?

    您正在输出这样的行:

    $dload = $GET_['downloadname'];
    $imagelink = $GET_['imagelink'];
    $title = $GET_['title'];
    while ($row = mysql_fetch_array($result)) 
    {
    echo "<li><a class =\"alldld\" href=\"$dload\" title=\"$title\"><img class=\"downloads\" src =\"$imagelink\"/>$title</a><br></li>";
    }
    }
    
    $dload=$GET_uuzy['downloadname'];
    $imagelink=$GET_u200;['imagelink'];
    $title=$GET_u3;['title'];
    while($row=mysql\u fetch\u数组($result))
    {
    回声“

  • ”; } }

    这有几个问题。首先,如果要从查询字符串中检索它,则需要使用
    $\u GET
    ,而不是
    $GET
    。其次,您不希望使用
    $\u GET
    从查询字符串中检索它;您想从
    $row
    检索它。第三,您需要将其放入
    while
    循环中。一旦您修复了这个问题,它应该可以工作。

    更改这部分代码

    $dload = $GET_['downloadname'];
    $imagelink = $GET_['imagelink'];
    $title = $GET_['title'];
    while ($row = mysql_fetch_array($result)) 
    {
    echo "<li><a class =\"alldld\" href=\"$dload\" title=\"$title\"><img class=\"downloads\" src =\"$imagelink\"/>$title</a><br></li>";
    }
    
    $dload=$GET_uuzy['downloadname'];
    $imagelink=$GET_u200;['imagelink'];
    $title=$GET_u3;['title'];
    while($row=mysql\u fetch\u数组($result))
    {
    回声“

  • ”; }

    while($row=mysql\u fetch\u array($result))
    {
    $dload=$row['downloadname'];
    $imagelink=$row['imagelink'];
    $title=$row['title'];
    回声“

  • ”; }
    从DB中检索时,需要使用获取值的数组,而不是
    $\u GET
    数组。此外,也没有
    $GET
    这样的东西


    重要注意事项:停止使用
    mysql
    函数,开始使用
    mysqli*
    函数或
    PDO
    。有关更多信息,请参阅
    $\u GET
    是包含URL中传递的值的数组

    <?php
    // Let's take the following URL
    // http://localhost/index.php?name=John&age=20
    echo $_GET["name"]; // Will display 'John'
    echo $_GET["age"];  // Will display '20'
    ?>
    
    <?php
    // Let's take the following URL
    // http://localhost/index.php?name=John&age=20
    echo $_GET["name"]; // Will display 'John'
    echo $_GET["age"];  // Will display '20'
    ?>
    
    <?php
    // ...
    
    while ($row = mysql_fetch_array($result)) {
        $dload = $row["downloadname"];
        $imagelink = $row["imagelink"];
        $title = $row["title"];
        echo "<li><a class =\"alldld\" href=\"$dload\" title=\"$title\"><img  class=\"downloads\" src =\"$imagelink\"/>$title</a><br></li>";
    }
    
    ?>