I'm trying to look for the text exist in the row inside the table called website.
Where uid
is INT and domain
is String.
If the Row is found and both uid
and domain
matches. It should output success
.
If the Row Value doesn't exist, it should output nothing
Both UID
and domain
are giving by the user in input form.
With the below code, It's not working. I'm not sure what I'm doing wrong.
$stmt = $conn->prepare('SELECT * FROM website WHERE uid=:uid AND domain=:domain');
$stmt->bindParam(1, $_GET['uid'], PDO::PARAM_INT);
$stmt->bindParam(2, $_GET['domain'], PDO::PARAM_STR);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row)
{
echo "found";
}
else {
echo "nothing";
}
With bindParam()
, the first parameter is the bind point. From the manual
Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form:name . For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter. (emphasis mine).
As you use named parameters in your SQL, you should use...
$stmt->bindParam('uid', $_GET['uid'], PDO::PARAM_INT);
etc.
(Not sure if there is a duplicate for this, will remove if one is found).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.