Cannot capture values entered in HTML form for MySQL
Posted: Tue Mar 11, 2008 12:02 pm
I profusely apologise if this is a repeated topic, however I have already searched this topic on the forum and tried to use the solution stated on the thread and I still cannot seem to get values recorded into MySQL.
Ok, so here's the full problem...
I can't seem to capture the values entered into the HTML registration form of a login/register system in order to create a new user record in the MySQL database.
When I run the code, the page shows a registration form, in which values can be entered. When I press the Submit button to enter the values, the next page shows a confirmation message stating that the details have been entered into the database. However, when I check the database to see if the values have been entered into the relevant table, a new row is created with the user details, but none of the details seem to have been captured. The cells in each column of the row are blank.
I have tested this code on its own as well as with the other bits of code to ensure that the security settings are not affecting the functioning of the login system, but it appears that there are no problems with the security settings or any other parts of the login system. It is just this bit of code that seems to be causing problems.
Please help me. I have tried everything I could possibly find on the internet. Nothing seems to work
This function is from a PHP file called database.php:
The following code is from a PHP file called register.php:
Ok, so here's the full problem...
I can't seem to capture the values entered into the HTML registration form of a login/register system in order to create a new user record in the MySQL database.
When I run the code, the page shows a registration form, in which values can be entered. When I press the Submit button to enter the values, the next page shows a confirmation message stating that the details have been entered into the database. However, when I check the database to see if the values have been entered into the relevant table, a new row is created with the user details, but none of the details seem to have been captured. The cells in each column of the row are blank.
I have tested this code on its own as well as with the other bits of code to ensure that the security settings are not affecting the functioning of the login system, but it appears that there are no problems with the security settings or any other parts of the login system. It is just this bit of code that seems to be causing problems.
Please help me. I have tried everything I could possibly find on the internet. Nothing seems to work
This function is from a PHP file called database.php:
Code: Select all
function addNewUser(){
$time = time();
/* If admin sign up, give admin user level */
if(strcasecmp($username, "admin") == 0){
$ulevel = 9;
}else{
$ulevel = 1;
}
$username = $_POST['username'];
$first = $_POST['userFirstName'];
$last = $_POSt['userLastName'];
$email = $_POST['userEmail'];
$password = $_POST['userPassword'];
$q = "INSERT INTO user (username, userFirstName, userLastName, userEmail,
userPassword, userLevel, timestamp) VALUES ('$username',
'$first','$last','$email','$password','1','1')";
return mysql_query($q, $this->connection);
}
Code: Select all
<?
include "session.php";
?>
<html>
<title>Registration Page</title>
<body>
<?
/**
* The user is already logged in, not allowed to register.
*/
if($session->logged_in){
echo "<h1>Registered</h1>";
echo "<p>We're sorry <b>$session->username</b>, but you've already registered. "
."<a href=\"main.php\">Main</a>.</p>";
}
/**
* The user has submitted the registration form and the
* results have been processed.
*/
else if(isset($_SESSION['regsuccess'])){
/* Registration was successful */
if($_SESSION['regsuccess']){
echo "<h1>Registered!</h1>";
echo "<p>Thank you <b>".$_SESSION['reguname']."</b>, your information has been added to the database, "
."you may now <a href=\"main.php\">log in</a>.</p>";
}
/* Registration failed */
else{
echo "<h1>Registration Failed</h1>";
echo "<p>We're sorry, but an error has occurred and your registration for the username <b>".$_SESSION['reguname']."</b>, "
."could not be completed.<br>Please try again at a later time.</p>";
}
unset($_SESSION['regsuccess']);
unset($_SESSION['reguname']);
}
/**
* The user has not filled out the registration form yet.
* Below is the page with the sign-up form, the names
* of the input fields are important and should not
* be changed.
*/
else{
?>
<h1>Register</h1>
<?
if($form->num_errors > 0){
echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>";
}
?>
<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>First Name:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>Email:</td><td><input type="text" name="email" maxlength="50" value="<? echo $form->value("email"); ?>"></td><td><? echo $form->error("email"); ?></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
<tr><td colspan="2" align="right">
<input type="hidden" name="subjoin" value="1">
<input type="submit" name = "submit" value="Join!"></td></tr>
<tr><td colspan="2" align="left"><a href="main.php">Back to Main</a></td></tr>
</table>
</form>
<?
}
?>
</body>
</html>