duanmu2015 2014-03-20 14:41
浏览 17

无法将数据从数据库显示到我的网站[关闭]

I have come across a problem when i try to display data from my database now I have never had this problem before and it will not show me any errors! can anyone see the problem with this? Any and all help is appreciated.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="Styles.css"/>
<?php
    error_reporting(E_ALL);
    $pagename=$_GET['Recipe'];
    $recipeID=$_GET['id'];
?>
<title><?php echo"$pagename"?></title>
</head>
<body>
<?php
    $mySqlHost='localhost';
    $mySqlUsername='';
    $mySqlPassword='';
    $mySqlDatabase='';
    $mySqlConnect=mysql_connect($mySqlHost,$mySqlUsername,$mySqlPassword) or die("Error Connecting to Database");
    mysql_select_db($mySqlDatabase,$mySqlConnect) or die ("Could not Select Database".mysql_error());

    $selectRecipeQuery="SELECT recipe_name,food_type_english FROM recipe WHERE recipe_id='$pagename'";
    $result=mysql_query($selectRecipeQuery) or die ("could not select data from table".mysql_error());

$tableRow=mysql_fetch_array($result);
        $recipe_name=$tableRow['recipe_name'];
        $food_type_english=$tableRow['recipe'];


    echo "<p>$recipe_name</p>";
    echo "<p>$food_type_english</p>";
?>
</body>
</html>

Please take a look to see if you can find out why it is not letting me display the data

  • 写回答

2条回答 默认 最新

  • dongzhuange2625 2014-03-20 14:54
    关注

    What about this?

    Just change myDatabase to your database name

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="Styles.css"/>
    <?php
        error_reporting(E_ALL);
        $pagename=$_GET['Recipe'];
        $recipeID=$_GET['id'];
    ?>
    <title><?php echo $pagename ?></title>
    </head>
    <body>
    <?php
    try {
        $conn = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);   
    
        $stmt = $conn->prepare('SELECT recipe_name,food_type_english FROM recipe WHERE recipe_id = :id');
        $stmt->execute(array('id' => $recipeID));
    
        while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            echo "<p>".$row['recipe_name']."</p>";
            echo "<p>".$row['food_type_english']."</p>";
        }
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
    ?>
    </body>
    </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助