Author Topic: any good form validations out there?  (Read 348 times)

0 Members and 1 Guest are viewing this topic.

Offline berry05Topic starter

  • Enthusiast
  • Posts: 204
  • Gender: Male
    • View Profile
any good form validations out there?
« on: December 08, 2008, 03:45:35 PM »
i googled php form validations and got nothing good..i'm trying to make a php register script that has a username, email, password1, password2...password1 and 2 cant be the same, they both have to be different and people cant register with the same username as somebody else or same email address as somebody else...any help? or any good php validation tuts? 

thxs!  :)

Offline berry05Topic starter

  • Enthusiast
  • Posts: 204
  • Gender: Male
    • View Profile
Re: any good form validations out there?
« Reply #1 on: December 08, 2008, 03:46:04 PM »
woops!
heres the code
Code: [Select]
<?php
$con 
mysql_connect("localhost","root","");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_select_db("register"$con);

$sql="INSERT INTO users (username, email, password1, password2)
VALUES
('
$_POST[username]','$_POST[email]','$_POST[password1]','$_POST[password2]')";

if (!
mysql_query($sql,$con))
  {
  die(
'Error: ' mysql_error());
  }
echo 
"Registration Success!!!";

mysql_close($con)
?>

Offline berry05Topic starter

  • Enthusiast
  • Posts: 204
  • Gender: Male
    • View Profile
Re: any good form validations out there?
« Reply #2 on: December 08, 2008, 06:39:45 PM »
anyone?

Offline gevans

  • Addict
  • Posts: 2,649
  • Gender: Male
  • don't shoot the messanger
    • View Profile
    • Guernsey Web Design
Re: any good form validations out there?
« Reply #3 on: December 08, 2008, 06:42:21 PM »
Hows your php?? Why don't you try writting your own?? ;)
I like starting my code with session_start();

Code: [Select]
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
Son of a biscuit eating bulldog
Use [code][/code] tags!!

Offline berry05Topic starter

  • Enthusiast
  • Posts: 204
  • Gender: Male
    • View Profile
Re: any good form validations out there?
« Reply #4 on: December 08, 2008, 06:45:12 PM »
lol i know but my php is horrible...i tried learning of of w3schools for a little more than a week and im trying to make a text based game and its not working out well because i havent made the registration script yet..i tried tuts and they work good on registration scripts but im trying to make one where you have 2 passwords and they have to be different and you have to enter your email address and you have to make  a user name also and i dont know what to do...the code on top is the code i have so far that puts the data submitted into the table..

Offline berry05Topic starter

  • Enthusiast
  • Posts: 204
  • Gender: Male
    • View Profile
Re: any good form validations out there?
« Reply #5 on: December 08, 2008, 06:52:21 PM »
heres the code you wanted...
Code: [Select]
<?php
$con 
mysql_connect("localhost","root","");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_select_db("register"$con);

$sql="INSERT INTO users (username, email, password1, password2)
VALUES
('
$_POST[username]','$_POST[email]','$_POST[password1]','$_POST[password2]')";

if (!
mysql_query($sql,$con))
  {
  die(
'Error: ' mysql_error());
  }
echo 
"Registration Success!!!";

mysql_close($con)
?>

Offline Blade280891

  • Addict
  • Posts: 2,496
  • Gender: Male
  • Mr.Grumpypants
    • View Profile
Read the rules http://www.phpfreaks.com/page/rules-and-terms-of-service#toc_forum_guidelines

Quote
99.9% of my replies are correct, the other 0.1% means you asked the wrong question

Offline gevans

  • Addict
  • Posts: 2,649
  • Gender: Male
  • don't shoot the messanger
    • View Profile
    • Guernsey Web Design
Re: any good form validations out there?
« Reply #7 on: December 08, 2008, 07:02:56 PM »
Code: [Select]
<?php
$con 
mysql_connect("localhost","root","");
if (!
$con) die('Could not connect: ' mysql_error());

mysql_select_db("register"$con);

$username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : FALSE;
$email = (isset($_POST['email'])) ? mysql_real_escape_string($_POST['email']) : FALSE;
$password1 = (isset($_POST['password1'])) ? md5($_POST['password1']) : FALSE;
$password2 = (isset($_POST['password2'])) ? md5($_POST['password2']) : FALSE;

if(!
$username) die('Username not set');
if(!
$email) die('Email not set');
if(!
$password1) die('Password1 not set');
if(!
$password2) die('Password2 not set');
if(
$password1 === $password2) die('Password1 and Password2 must be different');

$query "SELECT username,email FROM users";
$result mysql_query($query) or die('Error: ' mysql_error());
while(
$row mysql_fetch_assoc($result)){
   if(
$email == $row['email']) die('Email already in use');
   if(
$username == $row['username']) die('Username already in use');
}

$sql="INSERT INTO users (username, email, password1, password2) VALUES
('
{$username}','{$email','$password1}','{$password2}')";

$result mysql_query($sql) or die('Error: ' mysql_error());
echo 
"Registration Success!!!";

mysql_close($con)
?>

I like starting my code with session_start();

Code: [Select]
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
Son of a biscuit eating bulldog
Use [code][/code] tags!!