I am trying to make a registration form for my db called vixtay with a table called members. I need the form to input the new registrants details into the fields in members called Name, Email, Telephone, Username and password.
The form below seems to connect to the database but will not input the details or verify the password, can someone please help me with this.
MY attempt at a form:
<style type="text/css">
<!--
.style3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; }
-->
</style>
<title>Register</title><form method=post action=register_form.php?action=register name=s>
<table border="1" align="center">
<tr>
<td><span class="style3">
<label for="name">Name</label>
</span></td>
<td><input name="name" type="text" id="name" size="30"></td>
</tr>
<tr>
<td><span class="style3">
<label for="email">Email</label>
</span></td>
<td><input name="email" type="text" id="email" size="35"></td>
</tr>
<tr>
<td><span class="style3">
<label for="telephone">Telephone</label>
</span></td>
<td><input name="telephone" type="text" id="telephone" size="20"></td>
</tr>
<tr><td width="110"><span class="style3">Username:</span></td>
<td width="301"><input name=username type=text size="40" id="username"></td></tr>
<tr>
<td><span class="style3">Password:</span></td>
<td><input name=password type=password id="password" size="40"></td>
</tr>
<tr>
<td class="style3">Repeat Password:</td><td><label for="vpass"></label>
<input name="vpass" type="password" id="vpass" size="40"></td></tr>
<tr><td colspan=2 align=center><input type=submit value=Register></td></tr>
</table>
</form>
<?php
$hostname="hostname.com";
$username="username";
$password="password";
$dbname="vixtay";
$usertable="members";
mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
mysql_select_db($dbname);
if ($action == register) {
if (!$name ||!$email ||!$telephone ||!$username || !$password || !$vpass) {
print "You must fill out all fields.";
exit;
}
$dupe1 = mysql_num_rows(mysql_query("select * from members where username='$username'"));
if ($dupe1 > 0) {
print "Someone already has that username.";
exit;
}
$dupe2 = mysql_num_rows(mysql_query("select * from members where email='$email'"));
if ($dupe2 > 0) {
print "Someone already has that email.";
exit;
}
if ($password != $vpass) {
print "The passwords do not match.";
exit;
}
mysql_query("insert into members (Name, Email, Telephone, Username, Password) values('$name','$email','$telephone','$username','$password')");
print "You are now registered. Login.";
}
?>
Thank you very much for the advice. Can you tell me exactly where these would go in my form please
$name = $_POST['name'];
$email = $_POST['email']; or what ever the NAMES of inputs are.
and the ["name"] am I right in assuming that has to be spelt the same as in the table such as Name instead of name?
Many thanks.
Also would it be better to link a form to a php for processing instead of having it all in the same page?
The form below seems to connect to the database but will not input the details or verify the password, can someone please help me with this.
MY attempt at a form:
<style type="text/css">
<!--
.style3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; }
-->
</style>
<title>Register</title><form method=post action=register_form.php?action=register name=s>
<table border="1" align="center">
<tr>
<td><span class="style3">
<label for="name">Name</label>
</span></td>
<td><input name="name" type="text" id="name" size="30"></td>
</tr>
<tr>
<td><span class="style3">
<label for="email">Email</label>
</span></td>
<td><input name="email" type="text" id="email" size="35"></td>
</tr>
<tr>
<td><span class="style3">
<label for="telephone">Telephone</label>
</span></td>
<td><input name="telephone" type="text" id="telephone" size="20"></td>
</tr>
<tr><td width="110"><span class="style3">Username:</span></td>
<td width="301"><input name=username type=text size="40" id="username"></td></tr>
<tr>
<td><span class="style3">Password:</span></td>
<td><input name=password type=password id="password" size="40"></td>
</tr>
<tr>
<td class="style3">Repeat Password:</td><td><label for="vpass"></label>
<input name="vpass" type="password" id="vpass" size="40"></td></tr>
<tr><td colspan=2 align=center><input type=submit value=Register></td></tr>
</table>
</form>
<?php
$hostname="hostname.com";
$username="username";
$password="password";
$dbname="vixtay";
$usertable="members";
mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
mysql_select_db($dbname);
if ($action == register) {
if (!$name ||!$email ||!$telephone ||!$username || !$password || !$vpass) {
print "You must fill out all fields.";
exit;
}
$dupe1 = mysql_num_rows(mysql_query("select * from members where username='$username'"));
if ($dupe1 > 0) {
print "Someone already has that username.";
exit;
}
$dupe2 = mysql_num_rows(mysql_query("select * from members where email='$email'"));
if ($dupe2 > 0) {
print "Someone already has that email.";
exit;
}
if ($password != $vpass) {
print "The passwords do not match.";
exit;
}
mysql_query("insert into members (Name, Email, Telephone, Username, Password) values('$name','$email','$telephone','$username','$password')");
print "You are now registered. Login.";
}
?>
Thank you very much for the advice. Can you tell me exactly where these would go in my form please
$name = $_POST['name'];
$email = $_POST['email']; or what ever the NAMES of inputs are.
and the ["name"] am I right in assuming that has to be spelt the same as in the table such as Name instead of name?
Many thanks.
Also would it be better to link a form to a php for processing instead of having it all in the same page?