Validating...

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
rockinliam
Posts: 466
Joined: Sun Jun 07, 2009 11:26 am

Validating...

Post by rockinliam »

I'm tired and i know i have coded this like utter arse.
<?php
include_once 'connect.php';
include 'functions.php';
session_start();

if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}
else
{
echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
exit;
}
?>

<?php

$forename = $_POST['forename'];
$surname = $_POST['surname'];
$title = $_POST['title'];
$road = $_POST['road'];
$district = $_POST['district'];
$town = $_POST['town'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$hometel = $_POST['hometel'];
$mobtel = $_POST['mobtel'];
$email = $_POST['email'];
$pref = $_POST['pref'];

$vforename = checkTextRequired ($forename);
$vsurname = checkTextRequired ($surname);
$vtown = checkTextRequired ($town);
$vtitle = checkTextUnrequired ($title);
$vcounty = checkTextUnrequired ($county);
$vpostcode = checkPostcode ($postcode);
$vhometel = checkPhonenum ($hometel);
$vmobtel = checkPhonenum ($mobtel);
$vemail = checkEmail ($email);

$validate_array = array("$vforename", "$vsurname", "$vtitle", "$vtown", "$vcounty", "$vpostcode", "$vhometel", "$vmobtel", "$vemail");


$loop = 0;
while ( $loop < 9 ) {
$return == $validate_array[$loop];
if ( $return == true ) {
$loop = ($loop + 1);

}else{

echo "You have entered invalid data.";
exit;
}
}

$SQL = "INSERT into customers (forename , surname , title , road , district , town , county , postcode , hometel , mobtel , email , pref) VALUES ('$forename','$surname','$title' ,'$road' ,'$district' ,'$town' ,'$county' ,'$postcode' ,'$hometel' ,'mobtel' ,'$email' ,'$pref')";

mysql_query($SQL) or die("could not register");

print "Thank you for registering!";


echo " <A href='customers.php'>Customers...</a><br>";

?>
What i'm trying to do is put a bunch of returns from some validation functions i have made into an array. They will either be true or false and i want it to look through the array and if it sees the return of false i want it to fail, and if all return true i want it to write to the DB. My head hurts to much for me to figure it out. Il go to bed.
EDIT
I should also say what is happening at the moment......... might help.
It seems to completely ignore the validation, even when i know that i particular function will return false...
Fffffuuuuuuu. :P
Skillset: C/C++, OpenGL, C#, Lua, PHP, MySql, Web Dev etc.
Website: https://liam-griffiths.co.uk/
Klown
Posts: 89
Joined: Tue Feb 22, 2011 5:59 am

Re: Validating...

Post by Klown »

Code: Select all

$loop = 0;
while ( $loop < 9 ) {
$return == $validate_array[$loop];
if ( $return == true ) {
$loop = ($loop + 1);
i dont have a code editor open but maybe something like this might help..

Code: Select all

$loop = 0;
while ( $loop < 9 ) {
$return == $validate_array[$loop];
if ( $return == "true" ) {
$loop++;
if( $myGames != "Crap" ) {
  • please_donate( $money );
} else {
  • just_enjoy();
}
User avatar
rockinliam
Posts: 466
Joined: Sun Jun 07, 2009 11:26 am

Re: Validating...

Post by rockinliam »

To lazy to work it out. Work around!
<?php
include_once 'connect.php';
include 'functions.php';
session_start();

if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}
else
{
echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
exit;
}
?>

<?php

$forename = $_POST['forename'];
$surname = $_POST['surname'];
$title = $_POST['title'];
$road = $_POST['road'];
$district = $_POST['district'];
$town = $_POST['town'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$hometel = $_POST['hometel'];
$mobtel = $_POST['mobtel'];
$email = $_POST['email'];
$pref = $_POST['pref'];

$vforename = checkTextRequired ($forename);
if ($vforename == false){
echo = "Unvalid";
exit;
}
$vsurname = checkTextRequired ($surname);
if ($vsurname == false){
echo = "Unvalid";
exit;
}
$vtown = checkTextRequired ($town);
if ($vtown == false){
echo = "Unvalid";
exit;
}
$vtitle = checkTextUnrequired ($title);
if ($vtitle == false){
echo = "Unvalid";
exit;
}
$vcounty = checkTextUnrequired ($county);
if ($vcounty == false){
echo = "Unvalid";
exit;
}
$vpostcode = checkPostcode ($postcode);
if ($vpostcode == false){
echo = "Unvalid";
exit;
}
$vhometel = checkPhonenum ($hometel);
if ($vhometel == false){
echo = "Unvalid";
exit;
}
$vmobtel = checkPhonenum ($mobtel);
if ($vmobtel == false){
echo = "Unvalid";
exit;
}
$vemail = checkEmail ($email);
if ($vemail == false){
echo = "Unvalid";
exit;
}
else
{

$SQL = "INSERT into customers (forename , surname , title , road , district , town , county , postcode , hometel , mobtel , email , pref) VALUES ('$forename','$surname','$title' ,'$road' ,'$district' ,'$town' ,'$county' ,'$postcode' ,'$hometel' ,'mobtel' ,'$email' ,'$pref')";

mysql_query($SQL) or die("could not register");

print "Thank you for registering!";


echo " <A href='customers.php'>Customers...</a><br>";
}
?>
Skillset: C/C++, OpenGL, C#, Lua, PHP, MySql, Web Dev etc.
Website: https://liam-griffiths.co.uk/
User avatar
rockinliam
Posts: 466
Joined: Sun Jun 07, 2009 11:26 am

Re: Validating...

Post by rockinliam »

Double post...........

If anybody was thinking of helping me, it's ok i wrote it again... manually checking everything by hand. I realised how poorly i had originally coded it lol, im so lazy lol.

Code: Select all

<?php
  include_once 'connect.php';
  include 'functions.php';
  session_start();
  
  if (isset($_SESSION['player'])) {
      $player = $_SESSION['player'];
  } else {
      echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
      exit;
  }
?>

<?php
  $forename = $_POST['forename'];
  $surname = $_POST['surname'];
  $title = $_POST['title'];
  $road = $_POST['road'];
  $district = $_POST['district'];
  $town = $_POST['town'];
  $county = $_POST['county'];
  $postcode = $_POST['postcode'];
  $hometel = $_POST['hometel'];
  $mobtel = $_POST['mobtel'];
  $email = $_POST['email'];
  $pref = $_POST['pref'];
  
  $vforename = checkText($forename);
  $vsurname = checkText($surname);
  $vpostcode = checkPostcode($postcode);
  $vhometel = checkPhonenum($hometel);
  if ($mobtel != "") {
      $vmobtel = checkPhonenum($mobtel);
  }
  $vhometel2 = checkNumeric($hometel);
  if ($mobtel != "") {
      $vmobtel2 = checkNumeric($mobtel);
  }
  if ($forename != "") {
      if ($vforename == true) {
          if ($surname != "") {
              if ($vsurname == true) {
                  if ($title != "") {
                      if ($town != "") {
                          if ($postcode != "") {
                              if ($vpostcode == true) {
                                  if ($hometel != "") {
                                      if ($vhometel == true) {
                                          if ($vhometel2 == true) {
                                              if ($mobtel != "") {
                                                  if ($vmobtel == true) {
                                                      if ($vmobtel2 == true) {
                                                          echo "Invalid Mobile phone number. Please use only numbers.";
                                                          exit;
                                                      }
                                                  } else {
                                                      echo "Invalid Mobile phone number. Please use 11 characters...";
                                                      exit;
                                                  }
                                              }
                                              $SQL = "INSERT into customers (forename , surname , title , road , district , town , county , postcode , hometel , mobtel , email , pref) VALUES ('$forename','$surname','$title' ,'$road' ,'$district' ,'$town' ,'$county' ,'$postcode' ,'$hometel' ,'mobtel' ,'$email' ,'$pref')";
                                              
                                              mysql_query($SQL) or die("could not register");
                                              
                                              print "Thank you for registering!";
                                              
                                              
                                              echo " <A href='customers.php'>Customers...</a><br>";
                                          } else {
                                              echo "Invalid Home phone number. Please use only numbers.";
                                              exit;
                                          }
                                      } else {
                                          echo "Invalid Home phone number. Please use 11 characters...";
                                          exit;
                                      }
                                  } else {
                                      echo "Invalid Home phone number.Please enter some data.";
                                      exit;
                                  }
                              } else {
                                  echo "Invalid postcode. Please check it's a valid postcode.";
                                  exit;
                              }
                          } else {
                              echo "Invalid postcode.Please enter some data.";
                              exit;
                          }
                      } else {
                          echo "Invalid town.Please enter some data.";
                          exit;
                      }
                  } else {
                      echo "Invalid title.Please enter some data.";
                      exit;
                  }
              } else {
                  echo "Invalid surname. Please use only letters.";
                  exit;
              }
          } else {
              echo "Invalid surname.Please enter some data.";
              exit;
          }
      } else {
          echo "Invalid forename. Please use only letters.";
          exit;
      }
  } else {
      echo "Invalid forename.Please enter some data.";
      exit;
  }
?>
Skillset: C/C++, OpenGL, C#, Lua, PHP, MySql, Web Dev etc.
Website: https://liam-griffiths.co.uk/
Post Reply

Return to “Advanced Help and Support”