topflight Posted March 6, 2009 Share Posted March 6, 2009 This code it suppose to show errors if the fileds are empty and also if everyihng is ok it is suppose to insert the information in the database and shoot an email to the new member. Well it is not working and it is saying $error is an undefined vaiable on line 12 which is if (!$_POST['fname']){ $error .='No First name<br>'; please help. Thanks in advanced! <? include 'db.php'; session_start(); if(isset($_SESSION['LOGGEDIN'])==TRUE){ echo'You are already a member';} if(isset($_POST['apply'])){ if (!$_POST['fname']){ $error .='No First name<br>'; } if (!$_POST['lname']){ $error .='No Last name<br>'; } if (!$_POST['email']){ $error .='No Email Address<br>'; } if (!$_POST['vatsimid']){ $error .='No VATSIM ID<br>'; } if (!$_POST['hub']){ $error .='No Hub<br>'; } if (!$_POST['pwd']){ $error .='No Password<br>'; } if (!$_POST['pwdc']){ $error .='No Password Conformation<br>'; } if (!$_POST['emailc']){ $error .='No Conformation Email Address<br>'; } if ($_POST['thours']){ if (!$_POST['thoursc']){ $error .='No comments<br>'; }} if ($_POST['email'] != $_POST['emailc']){ $error .='Email mismatch'; } if ($_POST['pwd'] != $_POST['pwdc']){ $error .='Password mismatch'; } if ($error){ echo $error;?> <FORM><INPUT TYPE="BUTTON" VALUE="Fix Errors" ONCLICK="history.go(-1)"></FORM> <? } else { $cerror = count($error); $fpwd= $_POST['pwd']; $pwd = md5($fpwd); $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $pilotl= mysql_query("SELECT * FROM `pilots` WHERE hub='$_POST[hub]' ORDER BY login DESC LIMIT 1") or die(mysql_error()); $plrows = mysql_num_rows($pilotl); if ($plrows=="0"){ if ($_POST['hub']=="KPDX"){ $login = "1000"; } if ($_POST['hub']=="KLAX"){ $login = "2000"; } if ($_POST['hub']=="PANC"){ $login = "3000"; } if ($_POST['hub']=="KSEA"){ $login = "4000"; }} else { if($cerror =='0'){ while($plr = mysql_fetch_array($pilotl)){ $login = $plr[login]; } $login = $login + 1; $update = mysql_query("INSERT INTO pilots (login,pwd,fname,lname,email,hub,thours,thoursc,rating,vatsimid,date,ip,status,hm,ed,bm,active) VALUES ('$login','$pwd','$_POST[fname]','$_POST[lname]','$_POST[email]','$_POST[hub]','$_POST[thours]','$_POST[thoursc]','First Officer','$_POST[vatsimid]','$now','$ip','0','0','0',0,0)") or die(mysql_error()); $jto = "email"; $jsubject = "A new pilot has signed up"; $jjmessae = " A new pilot ($fname $laname) with the pending ID of ($login) has submitted an Applications with --------. Please activate their test. "; $from = "email"; $jheaders = "From: $from"; mail($jto, $jsubject, $jmessage, $jheaders); $to = "$email"; $subject = "RE:------ Application ($fname $lname)"; $messae = " Dear ($fname $lname), We have reccevied your application for membership with -----. You will reccevie another email within 24-48 hours regarding your entry exam. It is really importaint that you complete this exam ASAP. In order to have a membership account with Simulated Alaska you MUST pass this exam with an 80%. So in the meantime please look at the SOP's, explore the site, and study basic aircraft Maneuvers. The exam will cover(Simulated Alaska Operations, Basic Aircraft Maneuvers, and Basic Flying Skills. Once you have pass this test you will then recceive another email saying you have been accepted. Sincerly, -------- "; $from = "email"; $headers = "From: $from"; mail($to, $subject, $message, $headers); echo'<b>Application Sent ------- Staff</b>'; } } } } ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted March 6, 2009 Share Posted March 6, 2009 Can you put this line above all the lines which mention $error : $error = ''; Quote Link to comment Share on other sites More sharing options...
topflight Posted March 6, 2009 Author Share Posted March 6, 2009 So if (!$_POST['fname']){ $error .='No First name<br>'; } should be if (!$_POST['fname']){ $error =''; } I am not understanding it please give me an example. Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted March 6, 2009 Share Posted March 6, 2009 He means, change <? include 'db.php'; session_start(); if(isset($_SESSION['LOGGEDIN'])==TRUE){ echo'You are already a member';} ?> to <? include 'db.php'; session_start(); $error = ''; if(isset($_SESSION['LOGGEDIN'])==TRUE){ echo'You are already a member';} ?> Quote Link to comment Share on other sites More sharing options...
topflight Posted March 6, 2009 Author Share Posted March 6, 2009 I did that but all I get is just a white page it shows the apposite errors but it doesn't insert nor email. and I am not receiving any error messages. Quote Link to comment Share on other sites More sharing options...
topflight Posted March 6, 2009 Author Share Posted March 6, 2009 Anybody else knows what I can do? Quote Link to comment Share on other sites More sharing options...
btherl Posted March 6, 2009 Share Posted March 6, 2009 Can you replace this: if(isset($_POST['apply'])){ with this: if(isset($_POST['apply'])){ print "<br>Received the form - going to check its validity next<br>"; and see if the message shows up. Quote Link to comment Share on other sites More sharing options...
topflight Posted March 6, 2009 Author Share Posted March 6, 2009 I did that and I typed everything in all it does it shows that message since everything is ok it should email the new member and also add them to the database. What's next? Quote Link to comment Share on other sites More sharing options...
btherl Posted March 6, 2009 Share Posted March 6, 2009 Ok I've found the problem. It's your indentation. You need to write your code like this: if (something) { do something } else { do something else } Notice how everything inside is indented, making it clear what runs only if the "if" is matched. When you fix your indentation, the problem with your code will be obvious. Quote Link to comment Share on other sites More sharing options...
topflight Posted March 6, 2009 Author Share Posted March 6, 2009 So may you please give me an example on what I should do using my code becuase it seem like my indentation is right. Quote Link to comment Share on other sites More sharing options...
SieRobin Posted March 6, 2009 Share Posted March 6, 2009 That's pretty sloppy coding lol. Indent your If statements they look atrocious. I'm sorry if I sound rude but I agree with btherl, your problem will be very obvious when you do lol. Quote Link to comment Share on other sites More sharing options...
topflight Posted March 6, 2009 Author Share Posted March 6, 2009 Well I am confused on what I should do please help. Quote Link to comment Share on other sites More sharing options...
btherl Posted March 6, 2009 Share Posted March 6, 2009 topflight, the code you posted looks like this: if (something) { do something } else { if (somethingelse) { do something else } } What it should look like is this: if (something) { do something } else { if (somethingelse) { do something else } } The second version makes it very easy to see what is inside each "if" and what is not. Quote Link to comment Share on other sites More sharing options...
topflight Posted March 6, 2009 Author Share Posted March 6, 2009 Now my code looks like this: <? include 'db.php'; session_start(); if(isset($_SESSION['LOGGEDIN'])==TRUE){ echo'You are already a member ';} if(isset($_POST['apply'])){ if (!$_POST['fname']){ $error .='No First name<br>'; } if (!$_POST['lname']){ $error .='No Last name<br>'; } if (!$_POST['email']){ $error .='No Email Address<br>'; } if (!$_POST['vatsimid']){ $error .='No VATSIM ID<br>'; } if (!$_POST['hub']){ $error .='No Hub<br>'; } if (!$_POST['pwd']){ $error .='No Password<br>'; } if (!$_POST['pwdc']){ $error .='No Password Conformation<br>'; } if (!$_POST['emailc']){ $error .='No Conformation Email Address<br>'; } if ($_POST['thours']){ if (!$_POST['thoursc']){ $error .='No comments<br>'; }} if ($_POST['email'] != $_POST['emailc']){ $error .='Email mismatch'; } if ($_POST['pwd'] != $_POST['pwdc']){ $error .='Password mismatch'; } if ($error) { echo $error;?> <FORM><INPUT TYPE="BUTTON" VALUE="Fix Errors" ONCLICK="history.go(-1)"></FORM> <? } else { $cerror = count($error); $fpwd= $_POST['pwd']; $pwd = md5($fpwd); $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $pilotl= mysql_query("SELECT * FROM `pilots` WHERE hub='$_POST[hub]' ORDER BY login DESC LIMIT 1") or die(mysql_error()); $plrows = mysql_num_rows($pilotl); if ($plrows=="0"){ if ($_POST['hub']=="KPDX"){ $login = "1000"; } if ($_POST['hub']=="KLAX"){ $login = "2000"; } if ($_POST['hub']=="PANC"){ $login = "3000"; } if ($_POST['hub']=="KSEA"){ $login = "4000"; } } else { if($cerror =='0'){ while($plr = mysql_fetch_array($pilotl)){ $login = $plr[login]; } $login = $login + 1; $update = mysql_query("INSERT INTO `pilots` (login,pwd,fname,lname,email,hub,thours,thoursc,rating,vatsimid,date,ip,status,hm,ed,bm,active) VALUES ('$login','$pwd','$_POST[fname]','$_POST[lname]','$_POST[email]','$_POST[hub]','$_POST[thours]','$_POST[thoursc]','First Officer','$_POST[vatsimid]','$now','$ip','0','0','0',0,0)") or die(mysql_error()); $jto = "jobs@simulatedasa.org"; $jsubject = "A new pilot has signed up"; $jjmessae = " A new pilot ($fname $laname) with the pending ID of ($login) has submitted an Applications with Simulated Alaska. Please activate their test. "; $from = "jobs@simulatedasa.org"; $jheaders = "From: $from"; mail($jto, $jsubject, $jmessage, $jheaders); $jto = "email"; $jsubject = "A new pilot has signed up"; $jjmessae = " A new pilot ($fname $laname) with the pending ID of ($login) has submitted an Applications with --------. Please activate their test. "; $from = "email"; $jheaders = "From: $from"; mail($jto, $jsubject, $jmessage, $jheaders); $to = "$email"; $subject = "RE:------ Application ($fname $lname)"; $messae = " Dear ($fname $lname), We have reccevied your application for membership with -----. You will reccevie another email within 24-48 hours regarding your entry exam. It is really importaint that you complete this exam ASAP. In order to have a membership account with Simulated Alaska you MUST pass this exam with an 80%. So in the meantime please look at the SOP's, explore the site, and study basic aircraft Maneuvers. The exam will cover(Simulated Alaska Operations, Basic Aircraft Maneuvers, and Basic Flying Skills. Once you have pass this test you will then recceive another email saying you have been accepted. Sincerly, -------- "; $from = "email"; $headers = "From: $from"; mail($to, $subject, $message, $headers); echo'<b>Application Sent ------- Staff</b>'; } } } } ?> Quote Link to comment Share on other sites More sharing options...
topflight Posted March 6, 2009 Author Share Posted March 6, 2009 Also I am still getting Undefined variable: error on line 12 which is if (!$_POST['fname']){ $error .='No First name<br>'; } Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 6, 2009 Share Posted March 6, 2009 Hi This is with the indentation sorted out to make the flow more obvious. <?php include 'db.php'; $error = ''; session_start(); if(isset($_SESSION['LOGGEDIN'])==TRUE){ echo'You are already a member ';} if(isset($_POST['apply'])) { if (!$_POST['fname']){ $error .='No First name<br>'; } if (!$_POST['lname']){ $error .='No Last name<br>'; } if (!$_POST['email']){ $error .='No Email Address<br>'; } if (!$_POST['vatsimid']){ $error .='No VATSIM ID<br>'; } if (!$_POST['hub']){ $error .='No Hub<br>'; } if (!$_POST['pwd']){ $error .='No Password<br>'; } if (!$_POST['pwdc']){ $error .='No Password Conformation<br>'; } if (!$_POST['emailc']){ $error .='No Conformation Email Address<br>'; } if ($_POST['thours']){ if (!$_POST['thoursc']){ $error .='No comments<br>'; }} if ($_POST['email'] != $_POST['emailc']){ $error .='Email mismatch'; } if ($_POST['pwd'] != $_POST['pwdc']){ $error .='Password mismatch'; } if ($error) { echo $error;?> <FORM><INPUT TYPE="BUTTON" VALUE="Fix Errors" ONCLICK="history.go(-1)"></FORM> <?php } else { $cerror = count($error); $fpwd= $_POST['pwd']; $pwd = md5($fpwd); $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $pilotl= mysql_query("SELECT * FROM `pilots` WHERE hub='$_POST[hub]' ORDER BY login DESC LIMIT 1") or die(mysql_error()); $plrows = mysql_num_rows($pilotl); if ($plrows=="0") { if ($_POST['hub']=="KPDX") { $login = "1000"; } if ($_POST['hub']=="KLAX") { $login = "2000"; } if ($_POST['hub']=="PANC") { $login = "3000"; } if ($_POST['hub']=="KSEA") { $login = "4000"; } } else { if($cerror =='0') { while($plr = mysql_fetch_array($pilotl)) { $login = $plr[login]; } $login = $login + 1; $update = mysql_query("INSERT INTO `pilots` (login,pwd,fname,lname,email,hub,thours,thoursc,rating,vatsimid,date,ip,status,hm,ed,bm,active) VALUES ('$login','$pwd','$_POST[fname]','$_POST[lname]','$_POST[email]','$_POST[hub]','$_POST[thours]','$_POST[thoursc]','First Officer','$_POST[vatsimid]','$now','$ip','0','0','0',0,0)") or die(mysql_error()); $jto = "jobs@simulatedasa.org"; $jsubject = "A new pilot has signed up"; $jjmessae = " A new pilot ($fname $laname) with the pending ID of ($login) has submitted an Applications with Simulated Alaska. Please activate their test. "; $from = "jobs@simulatedasa.org"; $jheaders = "From: $from"; mail($jto, $jsubject, $jmessage, $jheaders); $jto = "email"; $jsubject = "A new pilot has signed up"; $jjmessae = " A new pilot ($fname $laname) with the pending ID of ($login) has submitted an Applications with --------. Please activate their test. "; $from = "email"; $jheaders = "From: $from"; mail($jto, $jsubject, $jmessage, $jheaders); $to = "$email"; $subject = "RE:------ Application ($fname $lname)"; $messae = " Dear ($fname $lname), We have reccevied your application for membership with -----. You will reccevie another email within 24-48 hours regarding your entry exam. It is really importaint that you complete this exam ASAP. In order to have a membership account with Simulated Alaska you MUST pass this exam with an 80%. So in the meantime please look at the SOP's, explore the site, and study basic aircraft Maneuvers. The exam will cover(Simulated Alaska Operations, Basic Aircraft Maneuvers, and Basic Flying Skills. Once you have pass this test you will then recceive another email saying you have been accepted. Sincerly, -------- "; $from = "email"; $headers = "From: $from"; mail($to, $subject, $message, $headers); echo'<b>Application Sent ------- Staff</b>'; } } } } ?> An obvious bug is that you set up a variable called $messae but then try and use $message to email (same for $jmessage / $jmessae and $jjmessage / $jjmessae). All the best Keith Quote Link to comment Share on other sites More sharing options...
topflight Posted March 6, 2009 Author Share Posted March 6, 2009 Also I fixed that email thing to: $jto = ""; $jsubject = ""; $jmessae = ". "; $from = ""; $jheaders = "From: $from"; mail($jto, $jsubject, $jmessage, $jheaders); $to = "$email"; $subject = ""; $message = "" $from = ""; $headers = "From: $from"; mail($to, $subject, $message, $headers); Also of course in my code the fields have data in it. and by the way I am sending to emails one to admin and one to the new member. I am also not receiving the undefined error no more but I am getting a white page when everything is ok. Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 6, 2009 Share Posted March 6, 2009 Hi Another error I have seen is that you get all the pilots and then loop through them until the last one, assigning $login, then once you have looped through them all you add one to $login and use that as the key. Couple of issues here. If 2 people at the same precise moment signed up you could get a duplicate, and more importantly you get all the pilots in descending order of login. So if you had 100 of them you would loop down from 100 to 1, then add 1 to 1 getting 2 and then try and insert the new pilot as login 2 (which probably already exists). At the very least take the DESC off the select of all the logins. Preferably change the structure of the table such that login is a key field and set up as "autonumber" (and in this way you could just insert to the table without specifying the login field and mysql would generate it for you), although this would upset your idea of having different ranges of login for different values of hub. Lastly you are checking $error and putting out a message if it is set. You then check for a count of the number of elements in the array $error (which isn't an array). My guess is that php is deciding that $error being a string is just an array of 1 element and putting 1 into $cerror, and so bypasses the whole emain step. All the best Keith Quote Link to comment Share on other sites More sharing options...
topflight Posted March 6, 2009 Author Share Posted March 6, 2009 I am confused this login thing has always work I am just trying to figure out how come it does not email the member and/also insert it into the database. Quote Link to comment Share on other sites More sharing options...
topflight Posted March 7, 2009 Author Share Posted March 7, 2009 Any other help? Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 7, 2009 Share Posted March 7, 2009 post your current code then tell us slowly what not working please. let start again. Quote Link to comment Share on other sites More sharing options...
topflight Posted March 7, 2009 Author Share Posted March 7, 2009 My code is a basic registration script. First it checks to make sure if all the fields are not empty if they are not then it will display an error message for that field or fields that is empty. Next it will md5 the password then it will give the user a login ID depending on the hub they choose. Then it adds one to the ID so if their is a 1000 id number in the database it will make the new member ID number 1001. After that it should insert it into the database. Then email the new member letting them know what happening to their account and also an admin letting them know they have to activate a new member. Here is my code: <?php include 'db.php'; $error = ''; session_start(); if(isset($_SESSION['LOGGEDIN'])==TRUE){ echo'You are already a member ';} if(isset($_POST['apply'])) { if (!$_POST['fname']){ $error .='No First name<br>'; } if (!$_POST['lname']){ $error .='No Last name<br>'; } if (!$_POST['email']){ $error .='No Email Address<br>'; } if (!$_POST['vatsimid']){ $error .='No VATSIM ID<br>'; } if (!$_POST['hub']){ $error .='No Hub<br>'; } if (!$_POST['pwd']){ $error .='No Password<br>'; } if (!$_POST['pwdc']){ $error .='No Password Conformation<br>'; } if (!$_POST['emailc']){ $error .='No Conformation Email Address<br>'; } if ($_POST['thours']){ if (!$_POST['thoursc']){ $error .='No comments<br>'; }} if ($_POST['email'] != $_POST['emailc']){ $error .='Email mismatch'; } if ($_POST['pwd'] != $_POST['pwdc']){ $error .='Password mismatch'; } if ($error) { echo $error;?> <FORM><INPUT TYPE="BUTTON" VALUE="Fix Errors" ONCLICK="history.go(-1)"></FORM> <?php } else { $cerror = count($error); $fpwd= $_POST['pwd']; $pwd = md5($fpwd); $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $pilotl= mysql_query("SELECT * FROM `pilots` WHERE hub='$_POST[hub]' ORDER BY login DESC LIMIT 1") or die(mysql_error()); $plrows = mysql_num_rows($pilotl); if ($plrows=="0") { if ($_POST['hub']=="KPDX") { $login = "1000"; } if ($_POST['hub']=="KLAX") { $login = "2000"; } if ($_POST['hub']=="PANC") { $login = "3000"; } if ($_POST['hub']=="KSEA") { $login = "4000"; } } else { if($cerror =='0') { while($plr = mysql_fetch_array($pilotl)) { $login = $plr[login]; } $login = $login + 1; $update = mysql_query("INSERT INTO `pilots` (login,pwd,fname,lname,email,hub,thours,thoursc,rating,vatsimid,date,ip,status,hm,ed,bm,active) VALUES ('$login','$pwd','$_POST[fname]','$_POST[lname]','$_POST[email]','$_POST[hub]','$_POST[thours]','$_POST[thoursc]','First Officer','$_POST[vatsimid]','$now','$ip','0','0','0',0,0)") or die(mysql_error()); $jto = "jobs@simulatedasa.org"; $jsubject = "A new pilot has signed up"; $jjmessae = " A new pilot ($fname $laname) with the pending ID of ($login) has submitted an Applications with Simulated Alaska. Please activate their test. "; $from = "jobs@simulatedasa.org"; $jheaders = "From: $from"; mail($jto, $jsubject, $jmessage, $jheaders); $jto = "email"; $jsubject = "A new pilot has signed up"; $jjmessae = " A new pilot ($fname $laname) with the pending ID of ($login) has submitted an Applications with --------. Please activate their test. "; $from = "email"; $jheaders = "From: $from"; mail($jto, $jsubject, $jmessage, $jheaders); $to = "$email"; $subject = "RE:------ Application ($fname $lname)"; $messae = " Dear ($fname $lname), We have reccevied your application for membership with -----. You will reccevie another email within 24-48 hours regarding your entry exam. It is really importaint that you complete this exam ASAP. In order to have a membership account with Simulated Alaska you MUST pass this exam with an 80%. So in the meantime please look at the SOP's, explore the site, and study basic aircraft Maneuvers. The exam will cover(Simulated Alaska Operations, Basic Aircraft Maneuvers, and Basic Flying Skills. Once you have pass this test you will then recceive another email saying you have been accepted. Sincerly, -------- "; $from = "email"; $headers = "From: $from"; mail($to, $subject, $message, $headers); echo'<b>Application Sent ------- Staff</b>'; } } } } ?> Thanks Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 7, 2009 Share Posted March 7, 2009 Hi Part of the issue is that we are now initialising $error. count($error) is meant to bring back the number of members in an array. Here is is being used to check if $error has been set, and having initialised it to "" it has been set so count returns 1. As count is non 0, if($cerror =='0') evaluates to false and so no email is sent nor is the database uploaded. It was a change to fix an error you had that caused us to suggest initialising $error. That it used to work and now didn't suggests possibly a php option has been changed. Simple solution is to change the line if($cerror =='0') to if($error !="") All the best Keith Quote Link to comment Share on other sites More sharing options...
topflight Posted March 7, 2009 Author Share Posted March 7, 2009 I have edited this part of my script: $cerror = count($error); if ($cerror > 1 ) { echo $error;?> <FORM><INPUT TYPE="BUTTON" VALUE="Fix Errors" ONCLICK="history.go(-1)"></FORM> <?php } else { and now I am not receiving no errors I click submit with no input field and it just gives me a white page. Quote Link to comment Share on other sites More sharing options...
topflight Posted March 7, 2009 Author Share Posted March 7, 2009 Any other suggestions? 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.