gpt4 book ai didi

PHP MYSQL GET方法和两个类

转载 作者:行者123 更新时间:2023-12-01 00:46:31 24 4
gpt4 key购买 nike

如果我有这样的 HTTP GET 方法 url http://www.mywebsite.com/page.php?q=Banana&NewYork香蕉在哪里水果类别和纽约是我的 mysql 数据库中的城市类别,我如何用 mysql 请求处理它这样在page.php中就会显示具体的url请求

php
$q= ($_GET['q']);
$q = htmlspecialchars($q);
$q = mysql_real_escape_string($q);

mysql
$req = $db->prepare ('SELECT * FROM tab WHERE ...');
$req->execute();

谢谢大家。

最佳答案

如果您的 URL 如下所示:...page.php?fruit=Banana&city=NewYork 您可以使用以下示例代码。

此外,您应该使用准备好的语句而不是 mysql_real_escape_string

<?php

$fruit = $_GET['fruit'];
$city = $_GET['city'];

//mysql
//Prepare the query and create a stmt
$req = $db->prepare("SELECT * FROM table_name WHERE fruit = ? AND city = ?");

//$req contains now a prepared statement - binding the parameters
//because at both "?" there are strings, there need to be "ss"
//The value of $fruit will be placed at the first ? - $city will be placed at the second ?
$req->bindParam("ss",$fruit,$city);

//Execute the statement
$req->execute();
?>

关于PHP MYSQL GET方法和两个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21431981/

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