I'm trying to set up a registration form with two parts. The select menu that appears in the second part depends on what's entered into the first part. I can get the second part of the form to display correctly, but after clicking the final submit button, none of the form data goes into the database and no error messages or anything display on the screen or in the source.
Here is my PHP (note - the database connection requirement has been altered for security):
<?php
require '../includes/functions.php';
require 'DBconnection';
require '../includes/header.htm';
?>
</td>
<td> </td>
<td class="main"> </td>
<td class="main" valign="top"><p class="title">UJ Member Registration</p>
<?php
if (isset ($_POST['submit'])) {
if (!empty ($_POST['ujname'])) {
$ujname = $_POST['ujname'];
$ujname = shortdbprep ($ujname);
} else {
$ujname = FALSE;
print "<p>Enter your playing name.</p>";
}
if (!empty ($_POST['password1'])) {
if ($_POST['password1'] == $_POST['password2']) {
$password1 = $_POST['password1'];
$password1 = shortdbprep ($password1);
} else {
$password1 = FALSE;
print "<p>Your confirmation password does not match your first password.</p>";
}
} else {
$password1 = FALSE;
print "<p>Please enter a password.</p>";
}
if (isset ($_POST['ujdivision'])) {
$ujdivision = $_POST['ujdivision'];
} else {
print "<p>You need to select a division.</p>";
}
if (!empty ($_POST['msn'])) {
$msn = $_POST['msn'];
$msn = shortdbprep ($msn);
} else {
$msn = FALSE;
print "<p>Enter your MSN ID.</p>";
}
if (isset ($_POST['rank_id'])) {
$rank_id = $_POST['rank_id'];
$position_id == 0;
}
if (isset ($_POST['position_id'])) {
$position_id = $_POST['position_id'];
$rank_id == 0;
}
if (!isset ($_POST['position_id']) && !isset ($_POST['rank_id'])) {
$rank_id = FALSE;
$position_id = FALSE;
print "<p>Please indicate your status in the clan.</p>";
}
if ($ujname && $password1 && $ujdivision && $rank_id && position_id && $msn) {
print "<p>{$ujname}</p>
<p>{$password1}</p>
<p>{$ujdivision}</p>
<p>{$rank_id}</p>
<p>{$position_id}</p>
<p>{$msn}</p>";
$query = "SELECT uj_id FROM ujmembers WHERE ujname='$ujname'";
$result = mysql_query ($query);
if (mysql_num_rows ($result) == 0) {
$query = "INSERT INTO ujmembers (uj_id, ujname, PASSWORD, ujmask, div_id, position_id, rank_id, msn) VALUES (0, '$ujname',
PASSWORD('$password1'), 1, '$ujdivision', '$position_id', '$rank_id', '$msn')";
$result = mysql_query ($query);
if ($result) {
print "<p>Thank you for registering! You now have access to the <a href=\"index.php\">Members Only</a> area.</p>";
} else {
print "<p>You could not be registered because: <b>".mysql_error()."</b>. The query was $query.</p>";
}
} else {
print "<p>That name has already been taken. Please choose another name.</p>";
}
}
} else {
print "<p>Please fill in all fields.</p>
<form action=\"registration.php\" method=\"post\" enctype=\"multipart/form-data\">";
echo divselect ();
print "<p>Playing name (no tags): <input name=\"ujname\" type=\"text\" size=\"50\" maxlength=\"255\" value=\"";
if (!empty ($_POST['ujname'])) {
print "{$_POST['ujname']}";
}
print "\" /></p>";
print "<p>MSN address: <input name=\"msn\" type=\"text\" size=\"50\" maxlength=\"255\" value=\"";
if (!empty ($_POST['msn'])) {
print "{$_POST['msn']}";
}
print "\" /></p>";
if (!isset ($_POST['continue']) || !isset ($_POST['ujdivision'])) {
if (isset ($_POST['continue']) && !isset ($_POST['ujdivision'])) {
print "<p>You must select a division before continuing.</p>";
}
print "<p><input name=\"continue\" type=\"submit\" value=\"Continue\" /></p>";
} else {
if ($_POST['ujdivision'] == 1 || $_POST['ujdivision'] == 2) {
echo rankselect ();
} else {
echo positionselect ();
}
print "<p>Password (between 4 and 20 characters): <input name=\"password1\" type=\"password\" size=\"20\"
maxlength=\"20\" /></p>
<p>Confirm password: <input name=\"password2\" type=\"password\" size=\"20\" maxlength=\"20\" /></p>
<p><input name=\"submit\" type=\"submit\" value=\"Register\" /></p>";
}
print "</form>";
?>
</td>
<?php
}
mysql_close();
require '../includes/footer.htm';
?>
Here are the custom functions I am using in my registration.php:
<?php
function shortdbprep ($text) {
$text = trim ($text);
$text = str_replace ("'", "''", $text);
return ($text);
unset ($text);
}
function longdbprep ($text) {
$text = trim ($text);
$text = str_replace ("'", "''", $text);
$text = nl2br ($text);
return ($text);
unset ($text);
}
function divselect () {
print "<fieldset>
<legend>Of which group are you a part?</legend>\n";
$query1 = "SELECT * FROM ujdivisions ORDER BY div_id ASC";
$result1 = mysql_query ($query1);
while ($array = mysql_fetch_array ($result1)) {
$div_id = $array['div_id'];
$div_name = $array['div_name'];
print "<p><input name=\"ujdivision\" type=\"radio\" value=\"{$div_id}\" ";
if ($_POST['ujdivision'] == $div_id) {
print "checked";
}
print "/>{$div_name}</p>\n";
}
print "</fieldset>\n";
}
function rankselect () {
print "<p><select name=\"rank_id\">
<option>Select your rank</option>";
$query2 = "SELECT * FROM ujranks WHERE rank_id > '0' ORDER BY rank_id DESC";
$result2 = mysql_query ($query2);
while ($array = mysql_fetch_array ($result2)) {
$rank_id = $array['rank_id'];
$rank_name = $array['rank_name'];
print "<option value=\"{$rank_id}\">{$rank_name}</option>\n";
}
print "</select></p>";
}
function positionselect () {
print "<p><select name=\"position_id\">
<option>Select your position</option>";
$query3 = "SELECT * FROM ujpositions WHERE position_id > '0' ORDER BY position_id ASC";
$result3 = mysql_query ($query3);
while ($array = mysql_fetch_array ($result3)) {
$position_id = $array['position_id'];
$pos_name = $array['pos_name'];
print "<option value=\"{$position_id}\">{$pos_name}</option>\n";
}
print "</select></p>";
}
?>
I know the connection to the database isn't the problem, because I use the same database connection for other parts of the site that do work.
Does anyone have any recommendations?
Thanks in advance.🙂