coldfiretech Posted August 31, 2008 Share Posted August 31, 2008 Okay i have a list of functions in one file called functions.php from page1.php i am calling the functions to validate some input from the user before moving on.. Im getting hung up on the cell phone field.. login and email work good.. hopefully someone will understand what ive got going on here! im stuck... any suggestions would be great functions.php <?php $db_user = "matt"; $db_pass = "password"; $db_db = "mydb"; $db_host = "localhost"; $con = mysql_connect($db_host, $db_user, $db_pass) or die('MySQl Connection Error:'.mysql_error()); function check_username($usernm) { global $db_db; global $con; mysql_select_db($db_db, $con) or die('MySQL Error: Cannot select table'); $q = "SELECT `login` from users WHERE login = '$usernm'"; $r = mysql_query($q, $con) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ //username already exists Return 0; }else{ //username doesnt exist Return 1; } mysql_close($con); } function check_email ($email) { global $db_db; global $con; mysql_select_db($db_db, $con) or die('MySQL Error: Cannot select table'); $q = "SELECT `email` from users WHERE email = '$email'"; $r = mysql_query($q, $con) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ //email already exists Return 0; }else{ //email doesnt exist Return 1; } mysql_close($con); } function check_cellphone($phone, $phone2) { global $db_db; global $con; mysql_select_db($db_db, $con) or die('MySQL Error: Cannot select table'); $q = "SELECT * from contact WHERE '$phone' or '$phone2' = ci_cell_phone"; $r = mysql_query($q, $con) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ //cell phone entered already exists Return 0; }else{ //cell phone entered is okay Return 1; } mysql_close($con); } function check_homephone($phone, $phone2) { global $db_db; global $con; mysql_select_db($db_db, $con) or die('MySQL Error: Cannot select table'); $q = "SELECT * from contact WHERE '$phone' or '$phone2' = ci_home_phone"; $r = mysql_query($q, $con) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ //home phone entered already exists Return 0; }else{ //home phone entered is okay Return 1; } } ?> and here is page1.php <?php include "test1.php"; $result = check_username("whambam"); $cellphone = "2532248006"; $homephone = "2532248007"; if ($result > 0) { //username is good to use //move to check email $result2 = check_email("flite67@yahoo.com"); if ($result2 > 0) { $result3 = check_cellphone($cellphone, $homephone); if (result3 > 0){ //cell phone is good / check home phone $result4 = check_homephone($cellphone, $homephone); if ($result4 > 0) { echo "everything is good to go"; //INSERT DATA INTO DATABASE } else { //home phone is no good echo "sorry but the home phone number you entered is already in our database "; } } else { echo "sorry but the cell phone number you entered is already in our database"; } } else { echo "bad email"; } } else { echo "bad username"; //username is already in use } ?> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted August 31, 2008 Share Posted August 31, 2008 Can you say return in uppercase? Yep. Sorry. Quote Link to comment Share on other sites More sharing options...
coldfiretech Posted August 31, 2008 Author Share Posted August 31, 2008 tried that i just turned on my error reporting and got this error Notice: Use of undefined constant result3 - assumed 'result3' in C:\wamp\www\cellsavior\page1.php on line 13 sorry but the cell phone number you entered is already in our database Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 31, 2008 Share Posted August 31, 2008 are u always returning a match on cell phone? if so I think its your where clause it should be more like <?php $q = "SELECT * from contact WHERE '$phone' = ci_cellphone or '$phone2' = ci_cell_phone"; Quote Link to comment Share on other sites More sharing options...
coldfiretech Posted August 31, 2008 Author Share Posted August 31, 2008 thats how i had it originally but i will try your syntax.. thanks cooldude! Quote Link to comment Share on other sites More sharing options...
coldfiretech Posted August 31, 2008 Author Share Posted August 31, 2008 okay i tried that and im still getting this Notice: Use of undefined constant result3 - assumed 'result3' in C:\wamp\www\cellsavior\page1.php_phpd_tmp49.php on line 13 sorry but the cell phone number you entered is already in our database EDIT OKAY SO I FORGOT THE $ !!! Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 31, 2008 Share Posted August 31, 2008 I do commend you on use my favorite style of error checking for queries where you pick that up from? Quote Link to comment Share on other sites More sharing options...
coldfiretech Posted August 31, 2008 Author Share Posted August 31, 2008 well, you know i just started php like a week and a half ago. but ive been reading alot... and really trying to buckle down and learn some of this... how did the rest of my code look? decent? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 31, 2008 Share Posted August 31, 2008 if u can write that in a week and a half I say throw it all out and redo it into an OOP method if you can learn OOP methods now you will save your self rewriting down the road. (not to say its bad it just has a very basic OOP look to it and OOP would make it 20 times better) Quote Link to comment Share on other sites More sharing options...
coldfiretech Posted August 31, 2008 Author Share Posted August 31, 2008 Know of any good tutorials? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 31, 2008 Share Posted August 31, 2008 http://www.phpfreaks.com/tutorials There are some basic OOP tutorials there here is my basic OOP register class (note input_clean is a function that strips tags and adds mysql_real_escape_string to the input custom function) <?php #class used to process a user registration class register_process{ #variable decleration var $submit = 0; var $sent = 0; var $email = ""; var $email2 = ""; var $password = ""; var $password2 = ""; var $securityq = ""; var $securitya = ""; var $true_captcha = ""; var $enter_captcha = ""; var $errors = array(); var $messages = array(); var $send_string = ""; var $userid = ""; #sets object's variable from defined POST inputs on the form. function define_inputs(){ $this->email = input_clean($_POST['email']); $this->email2 = input_clean($_POST['email2']); $this->password = input_clean($_POST['password']); $this->password2 = input_clean($_POST['password2']); $this->securityq = input_clean($_POST['secruity_question']); $this->securitya = input_clean($_POST['security_answer']); $this->true_captcha = $_SESSION['captcha']; $this->enter_captcha = input_clean($_POST['captcha']); } #errors reporting during class execution runs are ran using the $this->error_report() command function error_report($error,$type){ #Type 1 is an error message meanign "bad" if($type === 1){ $this->errors[] = $error; } #non type 1 errors are messages such as a successful update or change in data. else{ $this->messages[] = $error; } } #checks email various ways to verify its a proper email on multiple levels function check_email($email,$email2){ #verify that mail1 = mail2 so the user input is true to what they wished to typed if($email != $email2){ $this->error_report("The two emails provided did not match.",1); } #regex verification that the user supplied an address simlar to user@test.com $pattern = "^.+@[^\.].*\.[a-z]{2,}$"; if (!eregi($pattern, $email)){ $this->error_report("The email supplied did not match the criteria for a valid email address (example user@gmail.com)",1); } #verification user's entered addres is not already in the database as the email address is the user's login username $q = "Select Email from `".USERS_TABLE."` Where Email = '".$email."'"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ $this->error_report("The email provided is already registered.",1); } } #checks password for match, length and alphanumeric function check_password($password,$password2){ #verification user input is true to their intentions if($password != $password2){ $this->error_report("The two passwords provided did not match.",1); } #verification password is of the desired minimal 6 character length if(strlen($password) <5){ $this->error_report("The password must be at least 5 characters long.",1); } #regex verification password is alphanumeric only eregi is requried for non case specific pattern as given $pattern = "[A-Z0-9]"; if(!eregi($pattern,$password)){ $this->error_report("The password can only contain alphanumeric characters.",1); } } #checks that a valid security question is provided and an answer is given function check_security($q,$a){ #verify aganist cURL injection of an invalid security question from table $q = "Select QuestionID from `".SQ_TABLE."` Where QuestionID = '".$q."'"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) == 0){ $this->error_report("Please select a valid security question.",1); } #Verify an answer of at least 4 characters is given so it isn't left blank. if(strlen($a) < 3){ $this->error_report("Please provide a valid security answer.",1); } } #checks captcha entered for consistency function check_captcha($true,$enter){ #verify user cpatcha matchs visual image a cURL and CPU injection prevention technique if($true != $enter){ $this->error_report("The captcha code entered did not match.",1); } } #returns count number of errors of it is greatre than 0 form will not process function errors_return(){ return count($this->errors); } #displays errors as a list in the document function errors_display(){ echo "<ul class=\"errors\">\n"; foreach($this->errors as $value){ echo "<li>".$value."</li>\n"; } echo "</ul>\n"; } #displays messages as a list in the document function messages_display(){ echo "<ul class=\"messages\">\n"; foreach($this->messages as $value){ echo "<li>".$value."</li>\n"; } echo "</ul>\n"; } #md5 1-way encryption of a password for db entry. function crypt_pass($pass){ return md5($pass); } #used to set the user's activation string length is set to 24 characters and the function gen_string from the function's library is used (custom function) function set_string(){ $this->send_string = gen_string(24); } #processes form function send_form(){ #sets string $this->set_string(); #insert query $q = "Insert into `".USERS_TABLE."` (Email, Password, Date_Joined, Security_ID, Security_Answer,Active,Active_Code) VALUES( '".$this->email."', '".$this->crypt_pass($this->password)."', NOW(), '".$this->securityq."', '".$this->securitya."', '0', '".$this->send_string."' )"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); $this->sent = 1; #set's user id in the object $this->userid = mysql_insert_id(); } #sends user the email required to activate their accounts headers are tested and have worked successfully. function send_mail(){ $subject = "New Account Creation at ".EMAIL_DOMAIN; $headers = "From: ".EMAIL_DOMAIN." <info@".EMAIL_DOMAIN.">\r\n"; $headers .= "Reply-To: info@".EMALI_DOMAIN."\r\n"; $headers .= "Return-Path: info@".EMAIL_DOMAIN."\r\n"; $headers .= "BCC: info@".EMAIL_DOMAIN."\r\n"; $headers .= "X-Mailer: PHP/" . phpversion()."\r\n"; #activation email message. Must be tabbed left since it is a text message and not an html document. $message = " Welcome to ".EMAIL_DOMAIN."\n Your Account is currently NOT activated you can do so by going to http://".EMAIL_DOMAIN."/url/activate.php?id=".$this->userid."_".$this->send_string."\n Your username is this email address (".$this->email.")\n Your password is: ".$this->password."\n If you are having issues please contact the server administrators at info@".EMAIL_DOMAIN.".\n Thanks, ".EMAIL_DOMAIN."\n\n This is a auto-generated message please do not respond to it."; #verification mailer function works if(mail($this->email,$subject,$message,$headers)){ $this->error_report("You have been sent an email with information on activating your account.",2); } else{ $this->error_report("There was an issue sending your email",1); } } } #####END OF REGISTER CLASS ?> Quote Link to comment Share on other sites More sharing options...
coldfiretech Posted August 31, 2008 Author Share Posted August 31, 2008 Thank you very much! I will throw this into php designer and see what happens! I appreciate everyones help! cooldude..... what is that picture???? i cant figure it out? Quote Link to comment 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.