LearningCoder
07-10-2012, 10:13 PM
Hello, I have a site which allows user to register. It is working fine in WAMP and allows me to register many different usernames. When I upload it to my host, it is returning the error "Fill in all of the form.".
I think it must be hosting issue otherwise it wouldn't work in WAMP neither. The code fails at the if statement: if($user && $enc_pass && $email){ even though I have filled in all of the form.
<?php
session_start();
/*FUNCTION TO SANITIZE USER INPUT. RETURNS USER INPUT STRIPPED OF ANY SPECIAL CHARACTERS*/
function check_input($data) {
$illegalChars = array('!','@','#','$','%','^','&','*','(',')','+','=','-','[',']','.',';',',','/','{','}','|','"',':','<','>','?','~','£');
$data = str_replace($illegalChars,'',$data);
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data, ENT_QUOTES);
$data = mysql_real_escape_string($data);
return $data;
}
/*FUNCTION TO SEND EMAIL TO USER*/
function sendEmail($email, $user, $pass){
$code = rand(10000, 99999);
$to = $email;
$subject = "Welcome to the Deus Ex Demo Upload/Download Site";
$body = "Welcome, {$user}<br />";
$body .= "Username: {$user}<br />";
$body .= "Password: {$pass}<br />";
$body .= "Activation Code: {$code}";
if(mail($to, $subject, $body)){
}
else{
echo "<p>Message delivery failed...</p>";
}
}
$user = check_input($_POST['user']);
$pass = check_input($_POST['pass']);
$enc_pass = md5($pass);
$email = $_POST['email'];
if($user && $enc_pass && $email){
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$_SESSION["email"] = "Email is not valid";
header("Location: index.php");
}
else{
// Connect to server and select database.
require("connectdb.php");
$query = mysql_query("SELECT * FROM $tblname WHERE username='{$user}' or email='{$email}'");
$count = mysql_num_rows($query);
if($count >= 1){
$_SESSION["emailinuse"] = "Email AND/OR Username already in use.";
header("Location: index.php");
}
else{
$qry = mysql_query("INSERT INTO members VALUES('', '{$user}', '{$enc_pass}', '{$email}')")or die("error");
sendEmail($email, $user, $pass);
$_SESSION["registered"] = "You have successfully registered. Please check your email for login details.<a href='index.php'>Click here</a> to
return to the homepage to login.";
header("Location: registered.php");
}
}
}
else{
$_SESSION["fill"] = "Please fill in all of the form.";
header("Location: index.php");
}
?>
Does anyone know what could be the issue?
Kind regards,
LC.
I think it must be hosting issue otherwise it wouldn't work in WAMP neither. The code fails at the if statement: if($user && $enc_pass && $email){ even though I have filled in all of the form.
<?php
session_start();
/*FUNCTION TO SANITIZE USER INPUT. RETURNS USER INPUT STRIPPED OF ANY SPECIAL CHARACTERS*/
function check_input($data) {
$illegalChars = array('!','@','#','$','%','^','&','*','(',')','+','=','-','[',']','.',';',',','/','{','}','|','"',':','<','>','?','~','£');
$data = str_replace($illegalChars,'',$data);
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data, ENT_QUOTES);
$data = mysql_real_escape_string($data);
return $data;
}
/*FUNCTION TO SEND EMAIL TO USER*/
function sendEmail($email, $user, $pass){
$code = rand(10000, 99999);
$to = $email;
$subject = "Welcome to the Deus Ex Demo Upload/Download Site";
$body = "Welcome, {$user}<br />";
$body .= "Username: {$user}<br />";
$body .= "Password: {$pass}<br />";
$body .= "Activation Code: {$code}";
if(mail($to, $subject, $body)){
}
else{
echo "<p>Message delivery failed...</p>";
}
}
$user = check_input($_POST['user']);
$pass = check_input($_POST['pass']);
$enc_pass = md5($pass);
$email = $_POST['email'];
if($user && $enc_pass && $email){
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$_SESSION["email"] = "Email is not valid";
header("Location: index.php");
}
else{
// Connect to server and select database.
require("connectdb.php");
$query = mysql_query("SELECT * FROM $tblname WHERE username='{$user}' or email='{$email}'");
$count = mysql_num_rows($query);
if($count >= 1){
$_SESSION["emailinuse"] = "Email AND/OR Username already in use.";
header("Location: index.php");
}
else{
$qry = mysql_query("INSERT INTO members VALUES('', '{$user}', '{$enc_pass}', '{$email}')")or die("error");
sendEmail($email, $user, $pass);
$_SESSION["registered"] = "You have successfully registered. Please check your email for login details.<a href='index.php'>Click here</a> to
return to the homepage to login.";
header("Location: registered.php");
}
}
}
else{
$_SESSION["fill"] = "Please fill in all of the form.";
header("Location: index.php");
}
?>
Does anyone know what could be the issue?
Kind regards,
LC.