Jump to content

Recommended Posts

when the user sumbits the form it is inputtin the data into the data as just blanks :S, i has worked before i input the //checks if user has input text section

[code]<?php
include('connect1.inc');?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Booze Cruise Reg</title>

</head>
<body>

<?php
if(!$_POST['register']){echo'<p align="center"><strong>Member Registration</strong></p>
<form name="form1" method="POST" action="">
<p align="center">Username:  <input type="text" name="username"></p>
<p align="center">Password:  <input type="text" name="password"></p>
<p align="center">Firsname:  <input type="text" name="firstname"></p>
<p align="center">Surname:  <input type="text" name="surname"></p>
<p align="center">Address 1: <input type="text" name="address1"></p>
<p align="center">Address 2: <input type="text" name="address2"></p>
<p align="center">Town:      <input type="text" name="town"></p>
<p align="center">County:    <input type="text" name="county"></p>
<p align="center">Postcode:  <input type="text" name="postcode"></p>
<p align="center">Tel No:    <input type="text" name="telno"></p>
<p align="center">Mobile:    <input type="text" name="mobile"></p>
<p align="center">Email:    <input type="text" name="email"></p>
<p align="center"><input type="submit" name="register" value="Enter Details"></p></form>';}
//27
else{
//checks if user has input text
if ($username=$_POST['username'] == "")  { die ("No Username Input");}
if ($password=$_POST['password'] == "")  { die ("No Password Input");}
if ($firstname=$_POST['firstname'] == ""){ die ("No Fristname Input");}
if ($surname=$_POST['surname'] == "")    { die ("No Surname Input");}
if ($address1=$_POST['address1'] == "")  { die ("No Address Input");}
if ($town=$_POST['town'] == "")          { die ("No Town Input");}
if ($county=$_POST['county'] == "")      { die ("No County Input");}
if ($postcode=$_POST['postcode'] == "")  { die ("No Postcode Input");}
if ($email=$_POST['email'] == "")        { die ("No Email Input");}

//encrypts password server side into md5 32bytes
$password = stripslashes($password);
$password = md5($password);

$sql = "INSERT INTO member(Username,Password,Firstname,Surname,Address1,Address2,Town,County,Postcode,TelNo,Mobile,Email)
VALUES ('$username','$password','$firstname','$surname','$address1','$address2','$town','$county','$postcode','$telno','$mobile','$email')";

mysql_query($sql)             

or die(mysql_error());
//50
echo ("<meta http-equiv=\"Refresh\" content=\"2; URL=members.php\"/>Thank You! You will be redirected");}
?>
</body>
</html>[/code]
You cant validate a variable and assign it at once. This makes no sense...

[code=php:0]
if ($username=$_POST['username'] == "")  { die ("No Username Input");}
[/code]

Try...

[code=php:0]
if ($_POST['username'] == "")  {
  die("No Username Input");
} else {
  $username = $_POST['username'];
}
[/code]
again it still in putting blanks :(

would i work if i put

[code]if ($username=$_POST['username'] == "")  { die ("No Username Input");}else INSERT INTO member(Username) vaules ('$username')"; [/code]

im just tryin to validate weather or not a user has input a value
thorpe just said you cant do this:
[code]if ($username=$_POST['username'] == "")  {[/code]

Use the isset function then check the value of the variable like so:
[code=php:0]if(isset($_POST['username']) && !empty($_POST['username']))
{
    // valid
}
else
{
    // not valid
}[/code]

Also when validating form data do not kill the script for every check. Log the errors in an array then check if there any errors after you;ve validated all the fields. If there are errors log display them along with the form.  If there are no errors then continue on.
thanks wildteen88

[code]if(isset($_POST['username']) && !empty($_POST['username']))
{
    // valid
}
else
{
    // not valid
}[/code]

will i have to do this for each input and do i need to put anything in the //vaild and //not vaild parts??
im just a little confused on what to place inside the vaild and non vaild parts

will it be echo non vaild for non vaild :D

but how will i get it to contine to check the next input? will it be like this:

[code]if(isset($_POST['username']) && !empty($_POST['username']))
{
    // valid
         if(isset($_POST['password']) && !empty($_POST['password']))
        {
         // valid
          }
          else
        {
         echo non vaild
        }
}
else
{
    echo non vaild
}[/code]
Please I’m really lost with getting this working any help is well appreciated

[code]
<?php
include('connect1.inc');?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Booze Cruise Reg</title>

</head>
<body>

<?php
if(!$_POST['register']){echo'<p align="center"><strong>Member Registration</strong></p>
<form name="form1" method="POST" action="">
<p align="center">Username:  <input type="text" name="username"></p>
<p align="center">Password:  <input type="text" name="password"></p>
<p align="center">Firsname:  <input type="text" name="firstname"></p>
<p align="center">Surname:  <input type="text" name="surname"></p>
<p align="center">Address 1: <input type="text" name="address1"></p>
<p align="center">Address 2: <input type="text" name="address2"></p>
<p align="center">Town:      <input type="text" name="town"></p>
<p align="center">County:    <input type="text" name="county"></p>
<p align="center">Postcode:  <input type="text" name="postcode"></p>
<p align="center">Tel No:    <input type="text" name="telno"></p>
<p align="center">Mobile:    <input type="text" name="mobile"></p>
<p align="center">Email:    <input type="text" name="email"></p>
<p align="center"><input type="submit" name="register" value="Enter Details"></p></form>';}
//27
else{
//checks if user has input text
if ($username=$_POST['username'] == "")  { die ("No Username Input");}else {
    $username = $_POST['username'];}

if ($password=$_POST['password'] == "")  { die ("No Password Input");}else {
    $username = $_POST['password'];}

if ($firstname=$_POST['firstname'] == ""){ die ("No Fristname Input");}else {
    $username = $_POST['firstname'];}

if ($surname=$_POST['surname'] == "")    { die ("No Surname Input");}else {
    $username = $_POST['surname'];}

if ($address1=$_POST['address1'] == "")  { die ("No Address Input");}else {
    $username = $_POST['address1'];}

if ($town=$_POST['town'] == "")          { die ("No Town Input");}else {
    $username = $_POST['town'];}

if ($county=$_POST['county'] == "")      { die ("No County Input");}else {
    $username = $_POST['county'];}

if ($postcode=$_POST['postcode'] == "")  { die ("No Postcode Input");}else {
    $username = $_POST['postcode'];}

if ($email=$_POST['email'] == "")        { die ("No Email Input");}else {
    $username = $_POST['email'];}

//encrypts password server side into md5 32bytes
$password = stripslashes($password);
$password = md5($password);

$sql = "INSERT INTO member(Username,Password,Firstname,Surname,Address1,Address2,Town,County,Postcode,TelNo,Mobile,Email)
VALUES ('$username','$password','$firstname','$surname','$address1','$address2','$town','$county','$postcode','$telno','$mobile','$email')";

mysql_query($sql)             

or die(mysql_error());
//50
echo ("<meta http-equiv=\"Refresh\" content=\"2; URL=members.php\"/>Thank You! You will be redirected");}
?>
</body>
</html>
[/code]
i dnt really understand what your getting at lol

i think its something to do with this part

[code]if ($username=$_POST['username'] == "")  { die ("No Username Input");}else {
    $username = $_POST['username'];}[/code]

but i dnt know what to change, add, delete, loop :S
Read the other posts here.
Specifically this one: http://www.phpfreaks.com/forums/index.php/topic,120692.msg495350.html#msg495350

Don't call yourself stupid, just take the time to actually think about it and READ the answers you're given.
[code]if(isset($_POST['username']) && !empty($_POST['username']))
{
    // valid
}
else
{
    // not valid
}
[/code]
right from this then, what do i need to put in the vaild part?? $username = $_POST['username'];?
the non vaild could i put [code] die ("No Username Input"); [/code]
rite kinda sorted....

ive got some fields that i dont need a input for e.g. tel no, mobile 2nd line of address now as a test to see if the form was working the codes not inputting the data into the database is there a piece of code that will need to be used that will allow it to be blank / no entry

cheers
hi ive got the checks to work but for some reason my address2, telno and mobile fields will not input data into the databse now ive checked the spelling (in the code and database) and it seems fine can anyone spot owt' wrong?

[code]<?php
include('connect1.inc');?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Booze Cruise Reg</title>

</head>
<body>

<?php
if(!$_POST['register']){echo'<p align="center"><strong>Member Registration</strong></p>
<form name="form1" method="POST" action="">
<p align="center">Username:  <input type="text" name="username" maxlength="10"></p>
<p align="center">Password:  <input type="password" name="password" maxlength="10"></p>
<p align="center">Firsname:  <input type="text" name="firstname" maxlength="20"></p>
<p align="center">Surname:  <input type="text" name="surname" maxlength="20"></p>
<p align="center">Address 1: <input type="text" name="address1" maxlength="20"></p>
<p align="center">Address 2: <input type="text" name="address2" maxlength="20"></p>
<p align="center">Town:      <input type="text" name="town" maxlength="20"></p>
<p align="center">County:    <input type="text" name="county" maxlength="20"></p>
<p align="center">Postcode:  <input type="text" name="postcode" maxlength="7"></p>
<p align="center">Tel No:    <input type="text" name="telno" maxlength="12"></p>
<p align="center">Mobile:    <input type="text" name="mobile" maxlength="12"></p>
<p align="center">Email:    <input type="text" name="email" maxlength="30"></p>
<p align="center"><input type="submit" name="register" value="Enter Details"></p></form>';}
//27
else{
//checks if user has input text

if(isset($_POST['username']) && !empty($_POST['username']))
{
    // valid
$username = $_POST['username'];
}
else
{
    // not valid
die ("No Username Input");
}

if(isset($_POST['password']) && !empty($_POST['password']))
{
    // valid
$password = $_POST['password'];
}
else
{
    // not valid
die ("No Password Input");
}

if(isset($_POST['firstname']) && !empty($_POST['firstname']))
{
    // valid
$firstname = $_POST['firstname'];
}
else
{
    // not valid
die ("No Firstname Input");
}


if(isset($_POST['surname']) && !empty($_POST['surname']))
{
    // valid
$surname = $_POST['surname'];
}
else
{
    // not valid
die ("No Surname Input");
}

if(isset($_POST['address1']) && !empty($_POST['address1']))
{
    // valid
  $address1 = $_POST['address1'];
}
else
{
    // not valid
die ("No Address Input");
}

if(isset($_POST['town']) && !empty($_POST['town']))
{
    // valid
  $town = $_POST['town'];
}
else
{
    // not valid
die ("No Town Input");
}

if(isset($_POST['county']) && !empty($_POST['county']))
{
    // valid
  $county = $_POST['county'];
}
else
{
    // not valid
die ("No County Input");
}

if(isset($_POST['postcode']) && !empty($_POST['postcode']))
{
    // valid
  $postcode = $_POST['postcode'];
}
else
{
    // not valid
die ("No Postcode Input");
}

if(isset($_POST['telno']) && !empty($_POST['telno']))
{
    // valid
  $email = $_POST['telno'];
}
else
{
    // not valid
die ("No Tel No Input");
}

if(isset($_POST['mobile']) && !empty($_POST['mobile']))
{
    // valid
  $email = $_POST['mobile'];
}
else
{
    // not valid
die ("No Mobile No Input");
}

if(isset($_POST['email']) && !empty($_POST['email']))
{
    // valid
  $email = $_POST['email'];
}
else
{
    // not valid
die ("No Email Input");
}

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email)) {
        echo "The email you entered is not valid. Please try again. <br/>";
exit();
    }

//encrypts password server side into md5 32bytes
$password = stripslashes($password);
$password = md5($password);

$sql = "INSERT INTO member(Username,Password,Firstname,Surname,Address1,Address2,Town,County,Postcode,TelNo,Mobile,Email)
VALUES ('$username','$password','$firstname','$surname','$address1','$address2','$town','$county','$postcode','$telno','$mobile','$email')";

mysql_query($sql)             

or die(mysql_error());
//50
echo ("<meta http-equiv=\"Refresh\" content=\"2; URL=members.php\"/>Thank You! You will be redirected");}
?>
</body>
</html>[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.