I’m attempting at seeing if there is already a row in a table in my database. If there is a row then the php will redirect to a different page. If there isn’t a row, it will stay there. Here is the code that I have:
$sched_ex = $db->prepare("SELECT COUNT(1) FROM sched WHERE uid = '$uid'");
$sched_ex->execute();
if($sched_ex == 0) { ... } else { redirect }
I’m new to PDO, not sure what I need to do for it to work properly.
Edit:
$sched_ex = $db->prepare("SELECT COUNT(1) FROM sched WHERE uid = :uid");
$sched_ex->execute(array(':uid' => $uid));
if($sched_ex->fetchColumn() == 0) { a lot of html }
else {
?>
<script langauge="javascript">
window.location="../"
</script>
<?php
}
Header wasn’t working, so I used JavaScript. I doubt that’s the issue, though.
Firstly, use bound parameters to protect your self against injection attacks:
Secondly, as for your question:
(See: http://www.php.net/manual/en/pdostatement.fetchcolumn.php)