gpt4 book ai didi

php - 获取 SQL 语法错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:23:19 25 4
gpt4 key购买 nike

我试图在我的 php 代码中从我的应用程序中获取这两个值。但在这样做之前,我试图通过 URL 检查。但我的问题是,如果给出值手册,我会得到正确的输出,但是当我通过传递值来检查它时,我会收到语法错误。谁能帮我解决这个问题。

<?php
$hostname_localhost ="localhost";
$database_localhost ="mobiledb";
$username_localhost ="root";
$password_localhost ="";
$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
or
trigger_error(mysql_error(),E_USER_ERROR);
$response = array();
mysql_select_db($database_localhost, $localhost);

$day = $_POST['day'];
$Q = $_POST['Qno'];


// get a product from products table
$result = mysql_query("SELECT $Q FROM `Questions` WHERE `day`='$day'") or die(mysql_error());
//echo $result;

if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["question"] = array();

while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();


$product["question".$i] = $row["$Q"];

$i = $i + 1;

// push single product into final response array
array_push($response["question"], $product);


}


// success
$response["success"] = 1;

// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No users found";

// echo no users JSON
echo json_encode($response);
}



?>

最佳答案

I am trying to check through URL

据此,我假设您的意思是您正在尝试访问 url:

http://localhost/yoursite/yourpage?Qno=5&day=thing

在这种情况下,这些变量将作为 $_GET['Qno']$_GET['day'] 访问。

您可以使用 $_REQUEST['Qno']$_REQUEST['day'] 两种方式接收变量。当然,您的应用程序有很多安全漏洞,我什至都不会去碰。

关于php - 获取 SQL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18775786/

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