...

View Full Version : Some help with user registration pls!!



Hein
08-09-2012, 07: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>

AndrewGSW
08-09-2012, 08:22 PM
//Prevent SQL injections
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);

You haven't set these variables for $cell, etc..

Pl. surround your code examples in [ CODE ] [/ CODE ] tags (without the spaces) or, specific for PHP, [ PHP ] [ /PHP ].

Hein
08-09-2012, 09:45 PM
That should not be the problem since those variables does not write to the database.
But I tried it anyway but still no luck.

AndrewGSW
08-10-2012, 12:22 AM
Your OP was about the values for cellphone, phone etc. not be inserted into your database:


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.

And your query attempts to insert these values, but you haven't defined the corresponding variables:


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())
;

So I'm at a loss as to what you are asking :confused:

Hein
08-13-2012, 09:59 AM
Ok cool thanx you were right!
That was the problem:thumbsup:!
Now my next issue is the auto invoicing system!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum