Jump to content

Archived

This topic is now archived and is closed to further replies.

Cagecrawler

Data not retrieved from form...

Recommended Posts

I have written my own script for registering on my website, but when somebody registers, their details aren't stored in my database properly.  I've worked out that the data isn't being retrieved from the form, but I have no idea why.  $date is still being inserted into the database, so this confirms the fact that its a problem with the form.  Below is my code:
[u]The Register Form[/u]
[code]<form action="regprocess.php" method="post">
<table>
<tr>
<td colspan="2"><center>REGISTER</center></td>
<tr>
<tr>
<td>Username:</td>
<td><input type="text" name='post_user'></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name='post_pass'></td>
</tr>
<tr>
<td>Repeat Password:</td>
<td><input type="password" name='repeat_pass'></td>
</tr>
<tr>
<td>Email Address:</td>
<td><input type="text" name='post_email'></td>
</tr>
<tr>
<td><input type="submit" value="Submit" name="Submit"><input type="reset" value="Reset" name="Reset"></td>
<td></td>
</tr>
</table>
</form>[/code]

The PHP Code
[code]<?php

//Get form data + date
$username = $_POST['post_user'];
$password = $_POST['post_pass'];
$repeatpass=$_POST['repeat_pass'];
$email=$_POST['post_email'];
$date = date('j-n-y');

//Check all fields have been filled
if(empty($username)|| empty($password) || empty($repeatpass) || empty($email))
{
//Kill script.  Go fill in all the fields...
die("All fields need to be filled.  Please go back and try again");
}
else
{
if($password == $repeatpass)
{
//Connect to DB
include('include/connect.php');

//Insert data
mysql_query("INSERT INTO users(id,username,password,email,date) VALUES ('','$username','$password','$email','$date')") or die(mysql_error());

//Take to login page
echo("Thank you for registering.  You may now login <a href=\"login.php\">here</a>.");
}
else
{
echo("Passwords do not match.  Please go <a href=\"register.php\">back </a>and try again.");
}
}
?>
[/code]

Thanks in advance...

Share this post


Link to post
Share on other sites
before you entered the values into the database try echoing them out to make sure that are not null or empty

Share this post


Link to post
Share on other sites
Try debugging the variables...

[code]
<?php

<?php

//Get form data + date
$username = $_POST['post_user'];
$password = $_POST['post_pass'];
$repeatpass=$_POST['repeat_pass'];
$email=$_POST['post_email'];
$date = date('j-n-y');

echo $username;
echo $password;
echo $repeatpass;
echo $email;

exit(); //This exits the script so you can see the output...
?>
[/code]

Share this post


Link to post
Share on other sites
Hmm...

Well, it now works.  I have no idea what I've done to make it work.  But it works, so I'm happy...

Thanks for the help.  No doubt I'll be back sooner or later... :P

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.