Hi, after many years I find myself using PHP and mySQL again, and it seems much has changed, especially with regards to retired functions and new methodologies, and it's driving me a little round the bend trying to figure out what I feel should be basic.
So, to keep things simple, on one page I have an input box. In here, a person can type a value and use the Submit button. This then opens a new page and passes the submitted value.
So, on the second page, I have been taking the submitted value and trying to determine if it's already in the database and display a message to say it's already there or (end goal) to insert it into the table.
For now, I'm just trying to do a simple 'Yes, it's new/Sorry, have it already' message.
I've tried both SELECT COUNT(*) FROM myTable WHERE myField = "$myVar"' as well as the SQL in the example below.
Ultimately, I just want to run something like the above, check if the COUNT(*) is 0 or more, and return my message.
<?php
$myVar = htmlspecialchars($_GET["example"]);
$sql = 'SELECT * FROM myTable WHERE myField = "$myVar"';
$res = $conn->query($sql);
$count = $res->fetchColumn();
if ($count == 0)
echo 'That is a new one.';
else
echo 'That is already stored.';
?>
For the record the database connection is working fine and is included elsewhere and, I feel, likely not relevant here other than the appropriate terminology.