Hein
08-09-2012, 06:47 PM
Hi everyone so I have a problem with my code it registers the user but inserts only the username password and email.
I have other fields like cellphone, phone, fax and location please see below code and advise.
The fist one is the html form.
<code>
<html>
<body>
<form action="register.php" method="post">
Username: <input name="name" type="text" />
Surname: <input name="surname" type="text" />
Password: <input type="password" name="password" />
Email: <input name="email" type="text" />
Cellphone: <input name="cell" type="text" />
Phone: <input name="phone" type="text" />
Fax: <input name="fax" type="text" />
Location: <input name="location" type="text" />
<input type="submit" value="Submit" />
</body>
</html>
</code>
This is the register.php code
<php>
<?php
include("db.php");
if (isset($_POST['name']) && isset($_POST['surname']) && isset($_POST['password']) && isset($_POST['email'])
&& isset($_POST['cell']) && isset($_POST['phone']) && isset($_POST['fax']) && isset($_POST['location']))
{
//Prevent SQL injections
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
//Get MD5 hash of password
$password = md5($_POST['password']);
//Check to see if username exists
$sql = mysql_query("SELECT name FROM userReg1 WHERE name = '".$name."'");
if (mysql_num_rows($sql)>0)
{
die ("Username taken.");
}
mysql_query("INSERT INTO userReg1(name, surname, password, email, cell, phone, fax,
location) VALUES ( '$name', '$surname', '$password', '$email', '$cell', '$phone', '$fax',
'$location' )")
or die (mysql_error())
; echo ("Account created.");
}
?>
</php>
I have other fields like cellphone, phone, fax and location please see below code and advise.
The fist one is the html form.
<code>
<html>
<body>
<form action="register.php" method="post">
Username: <input name="name" type="text" />
Surname: <input name="surname" type="text" />
Password: <input type="password" name="password" />
Email: <input name="email" type="text" />
Cellphone: <input name="cell" type="text" />
Phone: <input name="phone" type="text" />
Fax: <input name="fax" type="text" />
Location: <input name="location" type="text" />
<input type="submit" value="Submit" />
</body>
</html>
</code>
This is the register.php code
<php>
<?php
include("db.php");
if (isset($_POST['name']) && isset($_POST['surname']) && isset($_POST['password']) && isset($_POST['email'])
&& isset($_POST['cell']) && isset($_POST['phone']) && isset($_POST['fax']) && isset($_POST['location']))
{
//Prevent SQL injections
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
//Get MD5 hash of password
$password = md5($_POST['password']);
//Check to see if username exists
$sql = mysql_query("SELECT name FROM userReg1 WHERE name = '".$name."'");
if (mysql_num_rows($sql)>0)
{
die ("Username taken.");
}
mysql_query("INSERT INTO userReg1(name, surname, password, email, cell, phone, fax,
location) VALUES ( '$name', '$surname', '$password', '$email', '$cell', '$phone', '$fax',
'$location' )")
or die (mysql_error())
; echo ("Account created.");
}
?>
</php>