Ok.
This is a really flexible, open-ended tutorial.
Enclose your form with a <p>. Then,
You start with the <form action="registration.php" method="post">
For every form, do some thing like
HTML Code:
<label for="email">Email: </label>
<input type="text" name="email"><br/>
And for the little *****'s for password, do this:
HTML Code:
<label for="password">Password: </label>
<input type="password" name="password"/><br/>
Just replace email with all the other info.
Once you're done, make a submit button.
HTML Code:
<input type="submit"/>
Now, this is really important. Make another php page nammed registration.php exactly, or whatever you put in action=.
Now, you're gonna have to learn a little bit of PHP. But for now, you're ok, I guess.
You start your PHP document like this.
On the next lines, you need the php code to take in the information the form just sent out.
This is done using $_POST.
This is how it's used:
PHP Code:
<?php
$email = $_POST['email'];
Change $email to whatever you need on your form.
BE CAREFUL! make sure the text you put inside the brackets for $_POST EXACTLY matches up with the name of the text element on your form.
Now, you need to check the information that you just got and see if it already exists, or if it is blank.
This is checking if it's blank.
PHP Code:
if ($email == null ||$password == null) //add more tests as needed.
{
die("You must fill out everything on the form!");
}
else
{
//continue...
}
So || in php means "or". If just one of the values is null, or nothing, the php script quits and tells the applicant.
In the else bracket, you want to first establish a connection with you sql database. In order to do this, you need your sql hostname, username, and password. This is how to establish a connection.
PHP Code:
$con = mysql_connect($host,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
}
Remeber! You want this to be in between the brackets of the first else{}
Replace $host, $username, and $password with whatever your mysql login info is.
Now, you want to point your code to the right database. This is done like this. This comes in between the second else{}.
PHP Code:
mysql_select_db("login",$con);
Again, replace "login" with whatever your database is named.
Now, we test if the info, such as email, has been already registered. So first, we query the email address from the database, and if it returns anything but a null, it has already been registered.
PHP Code:
//This comes AFTER the select db function.
$alreadyexists = mysql_query(SELECT password FROM login WHERE email = $email); //tries to search for the email
if ($alreadyexists != null) //sees if the email is already in the database.
{
die('This email has already been registered. Please use a different email.');
}
Hopefully, you see how that little snippet works.
Nextly, since everything is going great, we are going to take all the info the user submitted and plug it into the table.
PHP Code:
mysql_query("INSERT INTO Persons (email,password)
VALUES ($email,$password)");
Do this with all the information. Hopefully you made your table so all the columns accept 'varchar'. That is going to be vital. Now, go back into your database and see if it inserted correctly. If you need further help, PM me or go to
www.w3schools.com . Thanks and good luck