Here are two working examples that will get you going.
You will get better results by using num_rows
Using mysqli_* functions with prepared statements:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$DB_HOST = "xxx";
$DB_NAME = "xxx";
$DB_PASS = "xxx";
$DB_USER = "xxx";
$db = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if($db->connect_errno > 0) {
die('Connection failed [' . $db->connect_error . ']');
}
// $passkey = $_GET['ref'];
$passkey = mysqli_real_escape_string($db,$_GET['ref']);
$tbl_name = "yourtable";
// $query = "SELECT * FROM $tbl_name WHERE confirmCode=?";
$query = "SELECT confirmCode FROM $tbl_name WHERE confirmCode=?";
if ($stmt = $db->prepare($query)){
$stmt->bind_param("s", $passkey);
if($stmt->execute()){
$stmt->store_result();
if ($stmt->num_rows == 1){
echo "Code verified.";
exit;
}
else{
echo "Sorry.";
// uncomment below and delete the above echo
// header("HTTP/1.1 404 Not Found");
// header("Location: 404.php");
// exit;
}
}
}
Using mysql_* functions:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$connect = mysql_connect("xxx","xxx","xxx") or die("Error Connecting To MYSQL Server");
mysql_select_db("xxx") or die("Error connecting to database");
// $passkey = $_GET['ref'];
$passkey = mysql_real_escape_string($_GET['ref']);
$tbl_name = "yourtable";
$checkKey = "SELECT * FROM $tbl_name WHERE confirmCode ='$passkey'";
$confirmKey = mysql_query($checkKey);
if (mysql_num_rows($confirmKey)) {
echo "Code verified.";
}
else{
echo "Sorry.";
// uncomment below and delete the above echo
// header("HTTP/1.1 404 Not Found");
// header("Location: 404.php");
// exit;
}
Footnotes:
mysql_*
functions deprecation notice:
http://www.php.net/manual/en/intro.mysql.php
This extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used. See also the MySQL API Overview for further help while choosing a MySQL API.
These functions allow you to access MySQL database servers. More information about MySQL can be found at » http://www.mysql.com/.
Documentation for MySQL can be found at » http://dev.mysql.com/doc/.