You are viewing our Forum Archives. To view or take place in current topics click here.
PHP form to check with MySQL
Posted:

PHP form to check with MySQLPosted:

MD5
  • Rising Star
Status: Offline
Joined: Jan 26, 201113Year Member
Posts: 705
Reputation Power: 31
Status: Offline
Joined: Jan 26, 201113Year Member
Posts: 705
Reputation Power: 31
I don't have enough PHP-Fu to complete this without messing something up in the process

I'm looking for a way to have a form on a website that users can go to and enter an 8 digit number into the form and then have the form check with a MySQL database to see if that number exists in the database and if it does, reply YES, if not reply NO.

Can someone help me with this? I only need the form on a blank page I can take care of the styling of the page etc.
Thanks

-MD5
#2. Posted:
iyop45
  • Prospect
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83

<form action="process.php" method="post">
    <input name="digits" type="number"/>
</form>

Then the process.php:

<?php
    if(isset($_POST['digits'])){
        if($stmt = $mysqli->prepare("SELECT 1 FROM `table` WHERE `digits` = ? LIMIT 1")){
            $stmt->bind_param('i',$_POST['digits']);
            $stmt->execute();
            if($stmt->num_rows()==1){
                echo 'YES';
            }else{
                echo 'NO';
            }
        }else{
            echo 'Failed to prepare query';
        }
    }else{
        echo 'Invalid request';
    }
?>

Of course you could remove the query limit if the column field is unique and/or primary.
Just make sure $mysqli is previously assigned object for your mysql connection.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.