Tom Hutchison Tom Hutchison - 2 years ago 71
PHP Question

PHP/SQL Issue when checking table information if exists

One of my pages will display information from the table if the information exists, however it's outputting an error stating it does not exist.

$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>

Information exists in this table and for the specific provider_seo_name but for some reason it won't allow it to display or thinks it doesn't exist. I was having issues with the extensions of the page before and the edit I made was adding .php to locations

I've googled possible causes but I can't figure it out. If you need more information I'll be happy to provide it

Answer Source
// 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

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

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download