I made two scripts register.php and register1.php, the register.php takes the values and register1.php process them and stores them into a mysql database.
after i fill in the form and press submit, I get an error. I am using mySQL 5.5.8
Register.php
<?php
include("header.html");
include("nav.html");
include("sidebars.html");
?>
<html>
<form action="register1.php" method="post">
<fieldset>
<legend>Form 1</legend>
First Name : <input type="text" name="fname"><br><br>
Last Name : <input type="text" name="lname"><br><br>
Email : <input type="text" name="email"><br><br>
Password : <input type="password" name="pass1"><br><br>
Re-enter pass : <input type="password" name="pass2"><br><br>
<input type="submit" name="submit" value="Register Now">
<input type="hidden" name="submitted" value="TRUE">
</fieldset>
</form>
</html>
<?php
include("footer.html");
?>
Register1.php
<?php
include("header.html");
include("nav.html");
include("sidebars.html");
?>
<?php
$errors=array();
if(isset($_POST['submitted'])){
if(empty($_POST['fname'])){
$errors[]="You forgot to enter first name";
}
else{
$fn=$_POST['fname'];
}
if(empty($_POST['lname'])){
$errors[]="You forgot to enter last name";
}
else{
$ln=$_POST['lname'];
}
if(empty($_POST['email'])){
$errors[]="You forgot to enter email";
}
else{
$email=$_POST['email'];
}
if(!empty($_POST['pass1']))
{
if(($_POST['pass1'])==($_POST['pass2']))
{
$pass=$_POST['pass1'];
}
else
{
$errors[]="The two passwords do not match";
}
}
else
{
$errors[]="You forgot to enter a password";
}
}
$r="";
if(empty($errors)){
require_once("connect.php");
$q='INSERT INTO users VALUES (3,"user3",SHA1("pass"),"$fn","$ln","$email")';
$r=mysql_query($q,$dbc);
}
if($r){
echo "You are now a registered user";
}
else{
echo "You could not be registered beacuse :-"."<br>";
foreach($errors as $msg){
echo $msg."<br>";
}
}
?>
<?php
include("footer.html");
?>
connect.php
<?php
{
DEFINE ("DB_USER","");
DEFINE ("DB_PASSWORD","");
DEFINE ("DB_HOST","localhost");
DEFINE ("DB_NAME","forums");
$dbc=mysql_connect(DB_HOST,DB_NAME) OR die("Could not connect to mySQL");
}
?>