Jump to content

[SOLVED] php verification help


fonecave

Recommended Posts

i have this code to add a user to a text document and am tryin to write it so that the user cant register an address that is already in the document but it only stops if the email address is typed in as nothing (blank) else it carries on and adds the lines anyway.

 

code is here

http://fonecave.110mb.com/code.txt

 

website is at http://fonecave.110mb.com/index.html

Link to comment
https://forums.phpfreaks.com/topic/74938-solved-php-verification-help/
Share on other sites

this will check for a valid email adress.

<?php

function  checkEmail($email) {
if (!preg_match
("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@
( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)) {
  return false;
}
return true;
}?>

 

 

checking to see if  email is already in database

 

<?php
$SQL = "SELECT * FROM email WHERE email = $email";
$result = mysql_query($SQL);
$num_rows = mysql_num_rows($result);
if ($num_rows > 0) {
echo "This email is already in use";}
?>

try this,

<?php
//$checkline="checkline"; //unused
$name=$_POST["name"];
$address=$_POST["address"];

if(empty($name) || empty($address))
{
echo "Please Enter name and email";
die;
}
//darkfreaks email checker
if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $address))
{
echo "Error, email not valid";
die;
}

$namelen=strlen($name);
if ($namelen<5)
{
echo "Error, name entered is under 5 characters long.";
die;
}

$efile=fopen("eregistrations.txt","a+") ;
if ($efile)
{
    $inuse = false;
    while ( !feof($efile) && !$inuse)
    {
        $f_name = trim(fgets($efile));
        $f_address = trim(fgets($efile));

        if($f_name == $name)
        {
        	echo "user '$name' is already used<br>\n";
		$inuse = true;
        }
        if($f_address == $address)
        {
        	echo "email '$address' is already used<br>\n";
		$inuse = true;
        }
    }
    if(!$inuse)
    {
	fwrite ($efile, $name . "\n");
	fwrite ($efile, $address . "\n");
	echo"Registration Succesful, Thank you $name";
	echo"<br>You will be one of the first to recieve all of our amazing offers!<br>" ;
	echo"You will recieve your username and password soon, Check your inbox.<br>" ;
	echo"Please click your browsers back button to return to fonecave.<br>" ;
    }
    fclose($efile);
}


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.