Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.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 如何使用mysqli在不同页面上使用链接提取数据_Php_Mysql_Mysqli - Fatal编程技术网

Php 如何使用mysqli在不同页面上使用链接提取数据

Php 如何使用mysqli在不同页面上使用链接提取数据,php,mysql,mysqli,Php,Mysql,Mysqli,我找到了链接到页面的方法,并设置了我想调用的ID: <a href="page.php?id=10">CLICK TEST</a> **(IS THIS RIGHT?)** 似乎我只能用MYSQL而不是MYSQLI来实现它。。。任何帮助都将不胜感激 更新代码: <?php $query = "select * from Drinklist where id = ?"; $result = mysqli_prepare($conn,$query); mysqli_s

我找到了链接到页面的方法,并设置了我想调用的ID:

<a href="page.php?id=10">CLICK TEST</a> **(IS THIS RIGHT?)**
似乎我只能用MYSQL而不是MYSQLI来实现它。。。任何帮助都将不胜感激

更新代码:

<?php
$query = "select * from Drinklist where id = ?";
$result = mysqli_prepare($conn,$query);
mysqli_stmt_bind_param($result, 'i', $_GET['id']);
mysqli_stmt_execute($result);
while($Drinklist = mysqli_fetch_array($result)){
        echo "<head>";
        echo "<title>".$Drinklist['name']." - Mixed Drinks Station</title>";
}
?>

获取错误:

<?php
$query = "select * from Drinklist where id = ?";
$result = mysqli_prepare($conn,$query);
mysqli_stmt_bind_param($result, 'i', $_GET['id']);
mysqli_stmt_execute($result);
while($Drinklist = mysqli_fetch_array($result)){
        echo "<head>";
        echo "<title>".$Drinklist['name']." - Mixed Drinks Station</title>";
}
?>
警告:mysqli_fetch_array()要求参数1为mysqli_结果, 对象在第6行的public_html/page.com/test/inc/drink-page.php中给出


好的,所以我最终通过大量的尝试和错误解决了这个问题

感谢chris85的早期支持,希望这能对您有所帮助。这很有趣;)


那么为什么要在查询中使用
?注意,get\u结果仅适用于mysqlnd。
-我之前尝试过发布和删除,但移动应用失败。
<?php
$query = "select * from Drinklist where id = ?";
$result = mysqli_prepare($conn,$query);
mysqli_stmt_bind_param($result, 'i', $_GET['id']);
mysqli_stmt_execute($result);
while($Drinklist = mysqli_fetch_array($result)){
        echo "<head>";
        echo "<title>".$Drinklist['name']." - Mixed Drinks Station</title>";
}
?>
<?php
$server = "localhost";
$user = "user";
$pass = "password";
$dbname = "database";

//Creating connection for mysqli

$conn = new mysqli($server, $user, $pass, $dbname);

//Checking connection

if($conn->connect_error){
 die("Connection failed:" . $conn->connect_error);
}

$article_id = $_GET['id'];

if( ! is_numeric($article_id) )
  die("Looks like you are lost!  <a href='#'>Back to Home</a> ");

$query = "SELECT * FROM `Whatever` WHERE `ID` =$article_id LIMIT 0 , 30";

$info = mysqli_query($conn,$query);

while($row = mysqli_fetch_array($info, MYSQL_ASSOC))
{

    $name = $Whatever['name'];
    $description = $Whatever['description'];
    $keywords = $Whatever['keywords'];
    $lrgpic = $Whatever['lrgpic'];
    $vid = $Whatever['vid'];

    $name = htmlspecialchars($row['name'],ENT_QUOTES);
    $description = htmlspecialchars($row['description'],ENT_QUOTES);
    $keywords = htmlspecialchars($row['keywords'],ENT_QUOTES);
    $lrgpic = htmlspecialchars($row['lrgpic'],ENT_QUOTES);
    $vid = $row['vid']; //Use <-- to be able to have HTML in your database otherwise the above would remove <, >, /, ', ", ect. 

        echo "<head>";
        echo "<title>$name - Site title</title>";
        echo "<meta name='description' content='$description'>";
        echo "<meta name='keywords' content='$keywords'>";
        include 'inc/head.php'; //includes already are in a php file ;)
        echo "</head>";
        echo "<body>";
        include 'inc/header.php';
        include 'inc/nav.php';
        echo "<div class='wrapper'>";
        echo "<div id='drink-name'>";
        echo "<h2>$name</h2>";
        echo "</div>";
        // AND SO ON
    }

?>