MackaDee
-
Posts
2 -
Joined
-
Last visited
Posts posted by MackaDee
-
-
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.
PHP & mySQL Returns
in PHP Coding Help
Posted
Thanks for replying, @Barand
when I do that, I get the following where Line 17 is $res->execute( [ $_GET["example"] ] );
Code is:
Ultimate goal is to pass the parameter to a new page, check if it's in the database and then insert it into the database if not, or display an informative message if so.