Hi all,
The following code displays the form, but when i click submit, it empties all of the fields. I get no error messages at all.
Im stumped
<?php
include("includes/connectpdomysql.php");
if (isset($user_username, $user_password, $user_email))
{
//Prevent SQL injections
$user_id = mysql_real_escape_string($_POST['user_id']);
$user_username = mysql_real_escape_string($_POST['user_username']);
$user_password = md5($_POST['user_password']);
$user_fname = mysql_real_escape_string($_POST['user_fname']);
$user_surname = mysql_real_escape_string($_POST['user_surname']);
$user_email = mysql_real_escape_string($_POST['user_email']);
$user_number = mysql_real_escape_string($_POST['user_number']);
$user_add1 = mysql_real_escape_string($_POST['user_add1']);
$user_add2 = mysql_real_escape_string($_POST['user_add2']);
$user_county = mysql_real_escape_string($_POST['user_county']);
$user_postcode = mysql_real_escape_string($_POST['user_postcode']);
$user_type = mysql_real_escape_string($_POST['user_type']);
$sql = "INSERT INTO users (user_id, user_username, user_password, user_fname, user_surname, user_email, user_number, user_add1, user_add2, user_county, user_postcode, user_type) VALUES (user_id, :user_username ,:user_password, :user_fname, :user_surname, :user_email, :user_number, :user_add1, :user_add2, :user_county, :user_postcode, :user_type)";
$q = $db->prepare($sql);
$q->execute(array(':user_id'=>$user_id,
':user_username'=>$user_username,
':user_title'=>$user_password,
'user_fname'=>$user_fname,
'user_surname'=>$user_surname,
':user_email'=>$user_email,
':user_number'=>$user_number,
':user_add1'=>$user_add1,
':user_add2'=>$user_add2,
':user_county'=>$user_county,
':user_postcode'=>$user_postcode,
':user_type'=>$user_type));
if(!$q)
{
die("Execute query error, because: ". $conn->errorInfo());
}
$q->setFetchMode(PDO::FETCH_BOTH);
// fetch
while($r = $q->fetch()){
print_r($r);
}
}
?>
<html>
<form action="newuser.php" method="post">
Username: <input name="user_username" type="text" /><br/>
Password: <input type="user_password" name="password" /><br/>
First name: <input name="user_fname" type="text" /><br/>
Surname: <input name="user_surname" type="text" /><br/>
Email: <input name="user_email" type="text" /><br/>
Contact number: <input name="user_number" type="text" /><br/>
Address line 1: <input name="user_add1" type="text" /><br/>
Address line 2: <input name="user_add2" type="text" /><br/>
County: <input name="user_county" type="text" /><br/>
Post Code: <input name="user_postcode" type="text" /><br/>
User Type: <input name="user_type" type="text" /><br/>
<input type="submit" value="Submit" /><br/>
</form>
</html>