Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.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 无法将数据库中的数据显示到我的网站_Php_Mysql - Fatal编程技术网

Php 无法将数据库中的数据显示到我的网站

Php 无法将数据库中的数据显示到我的网站,php,mysql,Php,Mysql,我遇到了一个问题,当我试图显示数据从我的数据库现在我从来没有这个问题之前,它不会向我显示任何错误!有人能看出这个问题吗?非常感谢您的帮助 <!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"> <

我遇到了一个问题,当我试图显示数据从我的数据库现在我从来没有这个问题之前,它不会向我显示任何错误!有人能看出这个问题吗?非常感谢您的帮助

<!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>

请看一看,您是否能找到为什么它不让我显示数据

这是怎么回事

只需将myDatabase更改为您的数据库名称

<!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>

您正在将
$pagename
而不是
$recipeID
传递给查询。您的查询应该是:

$selectRecipeQuery="SELECT recipe_name,food_type_english FROM recipe WHERE recipe_id='$recipeID'";

通过向查询传递错误的值,您不会得到没有错误的结果

我将是第一个这么说的人,因为总有人这么说。在继续开发之前,请考虑切换到最新的MySQL库。推荐的方法是pdo,但也有其他方法。这一行缺少分号:但这是除了@Chevi已经提到的以外,我能看到的唯一问题。您的主机是否升级了PHP和/或更改了PHP.ini?是否有人删除了您的数据库?也许使用SQL注入@Chevi我的sql已经过时了?我是一个二年级的网络学生,这是我被教导的方式,我使用为我们提供的内部服务器。你能解释一下你所说的mysql库是什么意思吗?@Website\u疯狂关于这个主题有很多资源,这个问题是我第一次发现的:。基本上,mysql库从一开始就存在,缺少许多有用和必要的元素。哇,我怎么没有看到这一点呢?谢谢你指出这一点,我已经尝试修复了一个多小时了!这难道不是一个打字错误问题,否定了答案(并要求投票结束)?