fonecave Posted October 26, 2007 Share Posted October 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/74938-solved-php-verification-help/ Share on other sites More sharing options...
darkfreaks Posted October 26, 2007 Share Posted October 26, 2007 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";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/74938-solved-php-verification-help/#findComment-378932 Share on other sites More sharing options...
atlanta Posted October 26, 2007 Share Posted October 26, 2007 You might want to use a database it is much easier to manage than using flatfile Quote Link to comment https://forums.phpfreaks.com/topic/74938-solved-php-verification-help/#findComment-378940 Share on other sites More sharing options...
darkfreaks Posted October 26, 2007 Share Posted October 26, 2007 agreed store the email in a database field and use the following code using mysql_num_rows to check for the same occuring adress. Quote Link to comment https://forums.phpfreaks.com/topic/74938-solved-php-verification-help/#findComment-378942 Share on other sites More sharing options...
MadTechie Posted October 26, 2007 Share Posted October 26, 2007 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74938-solved-php-verification-help/#findComment-378944 Share on other sites More sharing options...
darkfreaks Posted October 26, 2007 Share Posted October 26, 2007 thanks tech im not that familiar with read and w rite functions yet mainly database stuff Quote Link to comment https://forums.phpfreaks.com/topic/74938-solved-php-verification-help/#findComment-378945 Share on other sites More sharing options...
fonecave Posted October 27, 2007 Author Share Posted October 27, 2007 thanks guys that was great! the code works perfectly except the email preg_match function i had to tweal the code a little now it works perfect (touch wood cheers Quote Link to comment https://forums.phpfreaks.com/topic/74938-solved-php-verification-help/#findComment-378974 Share on other sites More sharing options...
darkfreaks Posted October 27, 2007 Share Posted October 27, 2007 your welcome click solved Quote Link to comment https://forums.phpfreaks.com/topic/74938-solved-php-verification-help/#findComment-378976 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.