So, wahts is the finished code - I've been having trouble with this.

So, wahts is the finished code - I've been having trouble with this.
Seen as it doesn't look like anyone else is going to post it:
Commented out mysql_real_escape_string because it only works if there's a database connection going on, didn't assume there was because there aren't any connections in the file.
PHP Code:<?php
//Clean function, comment out if not wanted.
function clean($this){
//$this = mysql_real_escape_string($this);
$this = strip_tags($this);
$this = htmlspecialchars($this, ENT_QUOTES);
$this = stripslashes($this);
return $this;
}
if(isset($_POST['submit'])){
//The form was sent, let's do some stuff!
$name = clean($_POST['name']);
$password = clean($_POST['password']);
$email = clean($_POST['email']);
$age = clean($_POST['age']);
if ($name == "")
{
echo "Whoops! You didn't enter a username. You need that if you want to login!";
exit;
}
if ($password == "")
{
echo "Whoops! You didn't enter a password. You need this to login to your account as well as security for your account!";
exit;
}
if ($email =="")
{
echo "Whoops! You didn't enter an email. You need this to receive news and updates for the usersystem, as well as to verify your identity.";
exit;
}
if ($age == "")
{
echo "Whoops! You didn't enter your age. We need this to verify you are old enough to register!";
exit;
}
echo("Heya, $name - Welcome to $site. The details you used to sign up are as follows:<br>
Name: $name<br />
Email: $email<br />
Age: $age<br />
<br />
If the details are incorrect, use the back button and try again. If they are correct, please continue to the installer.
");
}else{
//The form hasn't yet been sent! Display it.
echo("<form action=\"register2.php\" method=\"post\">
Username: <input type=\"text\" name\"name\"><br>
Password: <input type=\"text\" name\"password\"><br>
Email: <input type=\"text\" name=\"email\"><br>
Age: <input type=\"text\" name=\"age\"><br>
<input type=\"submit\" name=\"submit\" value=\"Submit\">
</form>
");
}
die();
?>
Last edited by lolwut; 21-11-2007 at 09:12 PM.
i've been here for over 8 years and i don't know why
Complete code:
PHP Code:<?php
//Clean function, comment out if not wanted.
function clean($string)
{
$string = htmlspecialchars($string, ENT_QUOTES);
if (get_magic_quotes_gpc())
{
$string = stripslashes($string);
}
$string = str_replace("\"", "", $string);
$string = htmlentities($string);
/**
* If you want SQL injection protection uncomment the next line
*/
// $string = mysql_real_escape_string($string);
return $string;
}
if ($_GET["action"] == "submit")
{
//The form was sent, let's do some stuff!
$name = clean($_POST["name"]);
$password = clean($_POST["password"]);
$email = clean($_POST["email"]);
$age = clean($_POST["age"]);
if ($name == "")
{
echo "Whoops! You didn't enter a username. You need that if you want to login!";
exit;
}
if ($password == "")
{
echo "Whoops! You didn't enter a password. You need this to login to your account as well as security for your account!";
exit;
}
if ($email == "")
{
echo "Whoops! You didn't enter an email. You need this to receive news and updates for the usersystem, as well as to verify your identity.";
exit;
}
if ($age == "")
{
echo "Whoops! You didn't enter your age. We need this to verify you are old enough to register!";
exit;
}
echo "Heya, $name - Welcome to $site. The details you used to sign up are as follows:<br>
Name: $name<br />
Email: $email<br />
Age: $age<br />
<br />
If the details are incorrect, use the back button and try again. If they are correct, please continue to the installer.
";
exit;
}
//The form hasn't yet been sent! Display it.
echo ("<form action=\"register2.php\" method=\"post\">
Username: <input type=\"text\" name\"name\"><br>
Password: <input type=\"text\" name\"password\"><br>
Email: <input type=\"text\" name=\"email\"><br>
Age: <input type=\"text\" name=\"age\"><br>
<input type=\"submit\" name=\"submit\" value=\"Submit\">
</form>
");
?>
When I use it, I enter everything and it tells me, " Whoops! You didn't enter a username. You need that if you want to login!".
PHP Code:<?php
//Clean function, comment out if not wanted.
function clean($string)
{
$string = htmlspecialchars($string, ENT_QUOTES);
if (get_magic_quotes_gpc())
{
$string = stripslashes($string);
}
$string = str_replace("\"", "", $string);
$string = htmlentities($string);
/**
* If you want SQL injection protection uncomment the next line
*/
// $string = mysql_real_escape_string($string);
return $string;
}
if ($_GET["action"] == "submit")
{
//The form was sent, let's do some stuff!
$name = clean($_POST["name"]);
$password = clean($_POST["password"]);
$email = clean($_POST["email"]);
$age = clean($_POST["age"]);
if ($name == "")
{
echo "Whoops! You didn't enter a username. You need that if you want to login!";
exit;
}
if ($password == "")
{
echo "Whoops! You didn't enter a password. You need this to login to your account as well as security for your account!";
exit;
}
if ($email == "")
{
echo "Whoops! You didn't enter an email. You need this to receive news and updates for the usersystem, as well as to verify your identity.";
exit;
}
if ($age == "")
{
echo "Whoops! You didn't enter your age. We need this to verify you are old enough to register!";
exit;
}
echo "Heya, $name - Welcome to $site. The details you used to sign up are as follows:<br>
Name: $name<br />
Email: $email<br />
Age: $age<br />
<br />
If the details are incorrect, use the back button and try again. If they are correct, please continue to the installer.
";
exit;
}
//The form hasn't yet been sent! Display it.
echo ("<form action=\"register2.php\" method=\"post\">
Username: <input type=\"text\" name=\"name\"><br>
Password: <input type=\"text\" name\"password\"><br>
Email: <input type=\"text\" name=\"email\"><br>
Age: <input type=\"text\" name=\"age\"><br>
<input type=\"submit\" name=\"submit\" value=\"Submit\">
</form>
");
?>
Now, when I regsiter a new page doesn't show up, all that happens is the form comes up again.
PHP Code:<?php
//Clean function, comment out if not wanted.
function clean($string)
{
$string = htmlspecialchars($string, ENT_QUOTES);
if (get_magic_quotes_gpc())
{
$string = stripslashes($string);
}
$string = str_replace("\"", "", $string);
$string = htmlentities($string);
/**
* If you want SQL injection protection uncomment the next line
*/
// $string = mysql_real_escape_string($string);
return $string;
}
if ($_GET["action"] == "submit")
{
//The form was sent, let's do some stuff!
$name = clean($_POST["name"]);
$password = clean($_POST["password"]);
$email = clean($_POST["email"]);
$age = clean($_POST["age"]);
if ($name == "")
{
echo "Whoops! You didn't enter a username. You need that if you want to login!";
exit;
}
if ($password == "")
{
echo "Whoops! You didn't enter a password. You need this to login to your account as well as security for your account!";
exit;
}
if ($email == "")
{
echo "Whoops! You didn't enter an email. You need this to receive news and updates for the usersystem, as well as to verify your identity.";
exit;
}
if ($age == "")
{
echo "Whoops! You didn't enter your age. We need this to verify you are old enough to register!";
exit;
}
echo "Heya, $name - Welcome to $site. The details you used to sign up are as follows:<br>
Name: $name<br />
Email: $email<br />
Age: $age<br />
<br />
If the details are incorrect, use the back button and try again. If they are correct, please continue to the installer.
";
exit;
}
//The form hasn't yet been sent! Display it.
echo ("<form action=\"?action=submit\" method=\"post\">
Username: <input type=\"text\" name=\"name\"><br>
Password: <input type=\"text\" name\"password\"><br>
Email: <input type=\"text\" name=\"email\"><br>
Age: <input type=\"text\" name=\"age\"><br>
<input type=\"submit\" name=\"submit\" value=\"Submit\">
</form>
");
?>
Now it says "Whoops! You didn't enter a password. You need this to login to your account as well as security for your account!".
This is just plain silly. The file he has posted has NO database stuff whatsoever, so why do you need a cleaning function? If it's just displaying HTML then all you need is something like htmlentites & stripslashes :\
Okay, what is the point of the register script if he isn't going to register someone?
He is making a user system.. he is going to end up inserting it somewhere.. best to have a clean function :\
Want to hide these adverts? Register an account for free!