gpt4 book ai didi

检查表信息是否存在时的 PHP/SQL 问题

转载 作者:行者123 更新时间:2023-11-29 21:03:32 25 4
gpt4 key购买 nike

如果信息存在,我的一个页面将显示表中的信息,但它会输出错误,指出该信息不存在。

$get_provider = str_clean($_GET['provider']);

$provider_sql = mysql_query("SELECT * FROM `payment_providers` WHERE `provider_seo_name`='".$get_provider."'");
$row = mysql_fetch_array($provider_sql);

$check_provider = mysql_query("SELECT * FROM `payment_providers` WHERE `provider_seo_name`='".$get_provider."'");
$provider_exists = mysql_num_rows($check_provider);

\\\\\\\\\\\\\\\\\\\\\\\\\\\\

<?php if($provider_exists == 0) { ?>
<h2 class="page-header">Error!</h2>
<div class="alert alert-danger">You never specified a payment provider to redeem with.</div>
<?php } else { ?>
<h2 class="page-header"><?php echo $row['provider_name']; ?></h2>
<p><?php echo $row['provider_description']; ?></p>

此表中存在特定provider_seo_name 的信息,但由于某种原因,它不允许显示或认为它不存在。我之前遇到了页面扩展的问题,我所做的编辑是将 .php 添加到位置

我已经用谷歌搜索了可能的原因,但我无法弄清楚。如果您需要更多信息,我很乐意提供

最佳答案

// Database info
$host = "localhost";
$database = "crm";
$user = "root";
$password = "bijoux22";

// Create a database connection w/ PDO
$pdo = new PDO('mysql:host='.$host.';dbname='.$database.';charset=utf8', $user, $password);

// Make a prepared statemnt
$q = $pdo->prepare("SELECT * FROM `payment_providers` WHERE `provider_seo_name`= :provider");

// Execute it with your variables
$q->execute(array(":provider"=>$_GET['provider']));

// Get the results
$row = $q->fetch();

// check if there were matches
if(count($row)) // provider exists
else // provider doesn't exist

参见:http://php.net/manual/en/pdo.prepared-statements.php

关于检查表信息是否存在时的 PHP/SQL 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37017660/

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