php - 从 MySQL 数据库中获取记录的问题
问题描述
由于这个错误,我在从 MySQL 库获取数据时遇到了很大的问题:
警告:mysqli::close(): 无法在第 44 行的 /Applications/AMPPS/www/Maciej/search.php 中获取 mysqli
试图通过删除连接关闭的行来做一些事情,但最终结果只是没有请求数据的空白页。目标是制作与数据库连接的营养计算器。我试图测试代码是否可以得到任何结果,但如上所述它失败了。IDE 也向我发出尖叫,告诉我它无法解析请求中的列。谢谢您的帮助!
在提示中请写出哪一行可能是问题,因为我们之间的沟通会更好。如果您对代码本身有一些评论,那也会有很大的帮助。大家,谢谢你的帮助!
session_start();
require_once 'connect.php';
$conn = @new mysqli($host, $user, $password, $db_name, $db_table);
if ($conn->connect_errno!=0)
{
echo 'Error:'.$conn->connect_errno;
}
else
{
$product = $_GET['product'];
$amount = $_GET['amount'];
$sql = "SELECT * FROM Food_db, mytable WHERE Product = '$product'";
if($result = @$conn->query($sql))
{
$how_many = $result->num_rows;
if ($how_many==1 and $amount>0)
{
$row = $result->fetch_assoc();
$_SESSION['Product']= $row['Product'];
$_SESSION['Proteins']= $amount * $row['Proteins'];
$_SESSION['Fats']= $amount * $row['Fats'];
$_SESSION['Carbohydrates']= $amount * $row['Carbohydrates'];
$_SESSION['Calories']= $amount * $row['Calories'];
unset($_SESSION['Error']);
$result->close();
header('Location:result.php');
}else{
$_SESSION['Amount_error'] = 'You have to add amount!';
$_SESSION['Error:'] = 'Ups record not in base';
header('Location:index.php');
}
}
$conn->close();
}
解决方案
推荐阅读
- android - android app crash with database java.(lang.IllegalArgumentException: Account cannot be null)
- javascript - 使用 2 按钮将选择更改为输入
- android - 如何在不打开活动的情况下发送数据?
- rest - Sharepoint API URL 混淆
- c - 为什么 printf 中的 \n 不打印字符数组的值或旧值?
- python - 读取的 CSV 没有行
- r - 如何在 Shiny 应用程序中对两个变量使用 lapply?
- ipad - Visual Studio for Mac / iPad 设备 - 等待调试器连接
- ssl - 配置文件中的 webpack4 webpack-dev-server ssl
- java - 在多模块化项目中查看解析器配置