I've tried looking but cannot find why my code is not working.
Here is what I cannot get to work - the query doesn't return anything, in fact the processing stops at the execute.
If I hardcode the values in the execute
it works:
$CID = $_POST [ 'loginPageCID' ];
$LID = $_POST [ 'loginPageLID' ];
$PWD = $_POST [ 'loginPagePwd' ];
require_once('connectdb.php');
$sql = "
SELECT u.*, c.cname, c.cstatus
FROM t_users u, t_customers c
WHERE u.cid = ?
AND c.cid = u.cid
AND u.login_id = ?
AND u.pwhash = ?
";
$stmt = $conn->prepare ( $sql );
$stmt->execute (array(1, 'su1', 'hello'));
$row = $stmt->fetchAll();
With the above it works, but if I try to use variables the execute seems to silently fail:
$CID = $_POST [ 'loginPageCID' ];
$LID = $_POST [ 'loginPageLID' ];
$PWD = $_POST [ 'loginPagePwd' ];
require_once('connectdb.php');
$sql = "
SELECT u.*, c.cname, c.cstatus
FROM ids_users u, ids_customers c
WHERE u.cid = ?
AND c.cid = u.cid
AND u.login_id = ?
AND u.pwhash = ?
";
$stmt = $conn->prepare ( $sql );
$stmt->bindParam(1, $CID, PDO::PARAM_INT);
$stmt->bindParam(2, $LID, PDO::PARAM_STR);
$stmt->bindParam(3, $PWD, PDO::PARAM_STR);
$stmt->execute (); // fails here
$row = $stmt->fetchAll();
Edit:
connectdb.php is as follows:
$conn;
try {
$conn = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}