gpt4 book ai didi

PHP页面: No database selected issue

转载 作者:行者123 更新时间:2023-11-29 07:12:42 24 4
gpt4 key购买 nike

我收到第 13 行未选择数据库错误。这行代码是

$result = $mysqli->query($query) or die($mysqli->error." on line ".__LINE__);

数据库连接成功,但当我尝试打开“question.php”文件时出现此错误。

<?php
// Set question number
$number = (int) $_GET['n'];

/*
* Get Question
*/
$query = "SELECT * FROM questions WHERE questions.question_number = $number";

// Get Result

$result = $mysqli->query($query) or die($mysqli->error." on line ".__LINE__);

$question = $result->fetch_assoc();


/*
* Get Choices
*/
$query = "SELECT * FROM choices WHERE question_number = $number";

// Get Results
$choices = $mysqli->query($query) or die($mysqli->error.__LINE__);

?>

更新!

我的数据库连接:

<?php

// Create connection credentials
$db_host = 'localhost';
$db_name = 'quizzer';
$db_user= 'root';
$db_pass='';

// Create mysqli object

$mysqli = new mysqli($db_host, $db_user,$db_pass,$db_pass);

// Error handler
if($mysqli->connect_error){
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}

最佳答案

您有一个拼写错误,请写为:

$mysqli = new mysqli($db_host, $db_user,$db_pass,$db_name);

而不是:

$mysqli = new mysqli($db_host, $db_user,$db_pass,$db_pass);

关于PHP页面: No database selected issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39041745/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com