Hi Freaks!
I'm writing my first script from scratch.. best way to learn from everyone's advice i've seen.
My goal is to create a form whereby an individual inputs a username and email (these are then put into the variables $username and $email using the $_POST superglobal.
The part i'm stuck on is trying to sort through an existing database and check if the username exists, then i'd like to check if the email matches. All i'm trying to do is validate that they already exist in an existing table. If they don't, then i want to echo a message that says 'you must already be a member'.
The following is only a snippet of the code - the web form and previous mentioned variables are both working fine.
<?php
//Now check to see if these details are correct as per the airbrushforum database
//Connect to the database
$dbc = mysqli_connect('localhost', 'XXXXX', 'PWgoesHere', 'database name')
or die('Error connecting to MySQL server');
//Create the query and select all fields from the 'user' table
$query = "SELECT * FROM user";
$result = mysqli_query($dbc, $query)
or die('Error querying database');
//Create a row to loop through all results
$row = mysqli_fetch_array($result);
//Use a conditional statement to validate the email address and username - if either is incorrect then
//echo a message
//the following code is executing and echoing a list - how do i instead sort through the data to check
//the $username and $email variable against what is in the database?
do
{
echo $row['userid'] . ' ' . $row['email'] . '<br/>';
} while ($row = mysqli_fetch_array($result));
?>
//This is the basic conditional statement i need to check my data. (right?)
if ($row['username'] == $username && $row['email'] == $email)
{
//Execute the rest of the code here
}
else
{
//echo that they must be a member of the airbrushforum.
}
Can't figure out if i should be using a foreach loop? if i should be looping a conditional statement? advice?
If i've been unclear with anything i'm sure you'll let me know but please have patience with me, I don't seem to be picking up PHP as fast as i'd like to..