ChompGator Posted December 10, 2007 Share Posted December 10, 2007 Hey, Ive made a simple registration form, which submits and sends that person an email with a validation link - When visiting the URL where my form is, Im getting a parse error on line 5 - So here is my registration form, and I have a 'include('functions.php') as well - so I posted both scrips, tell me what you see wrong I unfortunately dont see anything wrong: registration.php <?php require_once('db.php'); include('functions.php); if(isset($_POST['register'])) { if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE) { $query = mysql_query("INSERT INTO jetblue (`Username` , `Password`, `Email`, `Random_key`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error()); $getUser = mysql_query("SELECT ID, Username, Email, Random_key FROM users WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error()); if(mysql_num_rows($getUser)==1) {//there's only one MATRIX :PP $row = mysql_fetch_assoc($getUser); $headers = 'From: postmaster@jetblue.com' . "\r\n" . 'Reply-To: postmaster@jetblue.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = "Activation email from ourdomainhere.com"; $message = "Dear ".$row['Username'].", this is your activation link to join our website. In order to confirm your membership please click on the following link: http://www.ourdomainhere.com/confirm.php?ID=".$row['ID']."&key=".$row['Random_key']." Thank you for joining"; if(mail($row['Email'], $subject, $message, $headers)) {//we show the good guy only in one case and the bad one for the rest. $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.'; } else { $error = 'I created the account but failed sending the validation email out. Please inform my boss about this cancer of mine'; } } else { $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.'; } } else { $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match'; } } ?> <?php if(isset($error)){ echo $error;}?> <?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br /> Password: <input type="password" id="password" name="password" size="32" value="" /><br /> Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br /> Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br /> <input type="submit" name="register" value="register" /><br /> </form> <? } ?> Functions.php <?php function EmailValidation($email) { $email = htmlspecialchars(stripslashes(strip_tags($email))); //parse unnecessary characters to prevent exploits if ( eregi ( '[a-z||0-9]@[a-z||0-9].[a-z]', $email ) ) { //checks to make sure the email address is in a valid format $domain = explode( "@", $email ); //get the domain name if ( @fsockopen ($domain[1],80,$errno,$errstr,3)) { //if the connection can be established, the email address is probabley valid return true; /* GENERATE A VERIFICATION EMAIL */ } else { return false; //if a connection cannot be established return false } } else { return false; //if email address is an invalid format return false } } ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 10, 2007 Share Posted December 10, 2007 Change include('functions.php); To include('functions.php'); Quote Link to comment Share on other sites More sharing options...
peranha Posted December 10, 2007 Share Posted December 10, 2007 include('functions.php); you missed the closing ' Quote Link to comment Share on other sites More sharing options...
ChompGator Posted December 10, 2007 Author Share Posted December 10, 2007 haha stupid ass mistake eh. Alright, works now, next problem is parse error on line 7 Quote Link to comment Share on other sites More sharing options...
ChompGator Posted December 10, 2007 Author Share Posted December 10, 2007 I tried editing line 7, but nothing worked, nothing I could think of at least. What happens is, the parse error isn't on the registration.php page, the parse error comes after you submit the form. Thanks Quote Link to comment Share on other sites More sharing options...
revraz Posted December 10, 2007 Share Posted December 10, 2007 You call valid_email & checkUnique functions, but in your functions file its called EmailValidation and I don't even see a checkUnique function. Quote Link to comment Share on other sites More sharing options...
ChompGator Posted December 10, 2007 Author Share Posted December 10, 2007 You know what I mis-read it, its actually a Fatal error: Call to undefined function valid_email() in D:\hosting\member\aiim\site2\registration.php on line 7 But it looks like you were right, let me fix it, Ill let you know if it worked! Thanks Quote Link to comment Share on other sites More sharing options...
ChompGator Posted December 11, 2007 Author Share Posted December 11, 2007 Hello, I have this registration script Im playing with, and Im getting a parse error on line 5, and Ill post the error below, also below is my script. I was wondering if someone could see the error on my line 5. Parse error: parse error, unexpected ';' in D:\hosting\member\aiim\site2\testing\registration.php on line 5 All the ';' I see on my line 5, belong there <?php require_once('db.php'); include('functions.php'); if($_GET['ID']!='' && numeric($_GET['ID'])==TRUE && strlen($_GET['key'])==32 && alpha_numeric($_GET['key'])==TRUE) { $query = mysql_query("SELECT ID, Random_key, Active FROM jetblue WHERE ID = '".mysql_real_escape_string($_GET['ID'])."'"); if(mysql_num_rows($query)==1) { $row = mysql_fetch_assoc($query); if($row['Active']==1) { $error = 'This member is already active !'; } elseif($row['Random_key']!=$_GET['key']) { $error = 'The confirmation key that was generated for this member does not match with the one entered !'; } else { $update = mysql_query("UPDATE jetblue SET Active=1 WHERE ID='".mysql_real_escape_string($row['ID'])."'") or die(mysql_error()); $msg = 'Congratulations ! You just confirmed your membership !'; } } else { $error = 'User not found !'; } } else { $error = 'Invalid data provided !'; } if(isset($error)) { echo $error; } else { echo $msg; } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted December 11, 2007 Share Posted December 11, 2007 Post your actual code. Line 5 in your last post is well foobar'd. Quote Link to comment Share on other sites More sharing options...
ChompGator Posted December 11, 2007 Author Share Posted December 11, 2007 Ok, my bad, here are my errors, I fixed some but I got more, this is on my fuctions page, Warning: Missing argument 3 for checkUnique(), called in D:\hosting\member\aiim\site2\testing\registration.php on line 7 and defined in D:\hosting\member\aiim\site2\testing\functions.php on line 7 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\hosting\member\aiim\site2\testing\functions.php on line 10 Warning: Missing argument 3 for checkUnique(), called in D:\hosting\member\aiim\site2\testing\registration.php on line 7 and defined in D:\hosting\member\aiim\site2\testing\functions.php on line 7 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\hosting\member\aiim\site2\testing\functions.php on line 10 Unknown column 'Email' in 'field list' Here is the registration page code <?php require_once('db.php'); include('functions.php'); if(isset($_POST['register'])) { if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE) { $query = mysql_query("INSERT INTO jetblue (`Username` , `Password`, `Email`, `Random_key`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error()); $getUser = mysql_query("SELECT ID, Username, Email, Random_key FROM users WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error()); if(mysql_num_rows($getUser)==1) {//there's only one MATRIX :PP $row = mysql_fetch_assoc($getUser); $headers = 'From: postmaster@jetbluevirtual.net' . "\r\n" . 'Reply-To: postmaster@jetbluevirtual.net' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = "Activation email from JetBlue Virtual"; $message = "Dear ".$row['Username'].", this is your activation link to join our website. In order to confirm your membership please click on the following link: http://www.ourdomainhere.com/confirm.php?ID=".$row['ID']."&key=".$row['Random_key']." Thank you for joining"; if(mail($row['Email'], $subject, $message, $headers)) {//we show the good guy only in one case and the bad one for the rest. $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.'; } else { $error = 'I created the account but failed sending the validation email out. Please inform my boss about this cancer of mine'; } } else { $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.'; } } else { $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match'; } } ?> <?php if(isset($error)){ echo $error;}?> <?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br /> Password: <input type="password" id="password" name="password" size="32" value="" /><br /> Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br /> Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br /> <input type="submit" name="register" value="register" /><br /> </form> <? } ?> Here is the script from my functions.php page <?php function valid_email($str) { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } function checkUnique($table, $field, $compared) { $query = mysql_query('SELECT '.mysql_real_escape_string($field).' FROM '.mysql_real_escape_string($table).' WHERE "'.mysql_real_escape_string($field).'" = "'.mysql_real_escape_string($compared).'"'); if(mysql_num_rows($query)==0) { return TRUE; } else { return FALSE; } } function random_string($type = 'alnum', $len = { switch($type) { case 'alnum' : case 'numeric' : case 'nozero' : switch ($type) { case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'numeric' : $pool = '0123456789'; break; case 'nozero' : $pool = '123456789'; break; } $str = ''; for ($i=0; $i < $len; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } return $str; break; case 'unique' : return md5(uniqid(mt_rand())); break; } } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted December 11, 2007 Share Posted December 11, 2007 The errors are pretty self explanatory. Did you write this code? Do you know how it works? checkUnique expects 3 arguments, here... checkUnique('Username', $_POST['username']) you only pass two. This causes a domino effect. Quote Link to comment Share on other sites More sharing options...
ChompGator Posted December 11, 2007 Author Share Posted December 11, 2007 Not all of it nope, I wrote all my other codes, but I couldn't figure this one out, so I copied and pasted some of the stuff, and figured I edited all the applicable code appropriately. Ill look more at it. Thanks 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.