Hi I'm new to php and I have some code that is supposed to check the input fields of my form and echo the proper message. Without the echoing of the message part, it just submits to the data base just fine. CAn someone please look at this code and tell me what is going wrong, cuz I sure don't know. <? session_start(); include("database.php"); $date = date("Y/m/d"); //see if name already exists in database function Name_Exists($Name){ global $conn; if(!get_magic_quotes_gpc()){ $Name = addslashes($Name); } $q = "select Name from members where Name = '$Name'"; $result = mysql_query($q,$conn); return (mysql_numrows($result) > 0); } /** * Inserts the given * into the database. Returns true on success, * false otherwise. */ function addNewUser($Name, $Phone, $Email, $State, $City, $Address, $Address2, $Referredby, $date){ global $conn; $q = "INSERT INTO members VALUES ('$Name', '$Phone', '$Email' , '$State' , '$City' , '$Address' , '$Address2' , '$Referredby', '$date')"; return mysql_query($q,$conn); } /** * Determines whether or not to show to sign-up form * based on whether the form has been submitted, if it * has, check the database for consistency and create * the new account. */ if(isset($_POST['submit'])){ /* Make sure all fields were entered */ if(!$_POST['name'] || !$_POST['phone'] || !$_POST['email'] || !$_POST['state'] || !$_POST['city'] || !$_POST['address']){ die('You didn\'t fill in a required field.'); } /* Spruce up username, check length */ $_POST['name'] = trim($_POST['name']); $_POST['phone'] = trim($_POST['phone']); $_POST['email'] = trim($_POST['email']); $_POST['state'] = trim($_POST['state']); $_POST['city'] = trim($_POST['city']); $_POST['address'] = trim($_POST['address']); $_POST['address2'] = trim($_POST['address2']); $_POST['referredby'] = trim($_POST['referredby']); if(Name_Exists($_POST['name'])){ $use = $_POST['name']; die("Sorry, the name: <strong>$use</strong> already exists in our records."); } $OK = 0; if(!$_POST['over_18'] || !$_POST['incomesource'] || !$_POST['checkingaccount'] || !$_POST['savingsaccount'] || !$_POST['legalservices'] || !$_POST['idt'] || !$_POST['compaccess'] || !$_POST['inetaccess'] || !$_POST['refer'] || !$_POST['oneyear'] || !$_POST['lessons'] || !$_POST['iagree']){ echo "<p> </p> <p> </p> <p> </p> <img src='coach2 update copy.jpg' align='top' border='0' width='71' height='88' style='position:absolute;left:20px;top:3px;width:71px;height:88px;z-index:'> <div style='position:absolute;left:110px;top:12px;width:324px;height:55px;z-index:' align='left'> <font style='font-size:48px' color='#000000' face='Eras Demi ITC'><b>CreditCoach</font><font style='font-size:24px' color='#000000' face='Eras Demi ITC'></b>™</font></div> <div style='position:absolute;left:64px;top:56px;width:409px;height:33px;z-index:' align='center'> <font style='font-size:21px' color='#000000' face='Papyrus'><b>We help you reach financial success</b></font></div>"; $OK = 1; } else{ echo "<p> </p> <p> </p> <p> </p> <img src='coach2 update copy.jpg' align='top' border='0' width='71' height='88' style='position:absolute;left:20px;top:3px;width:71px;height:88px;z-index:'> <div style='position:absolute;left:110px;top:12px;width:324px;height:55px;z-index:' align='left'> <font style='font-size:48px' color='#000000' face='Eras Demi ITC'><b>CreditCoach</font><font style='font-size:24px' color='#000000' face='Eras Demi ITC'></b>™</font></div> <div style='position:absolute;left:64px;top:56px;width:409px;height:33px;z-index:' align='center'> <font style='font-size:21px' color='#000000' face='Papyrus'><b>We help you reach financial success</b></font></div> <p> </p><p align='left'><u><font color='#FF0000'> <a href='http://www.youronlinecreditcoach.com/register.php'> <font color='#FF0000' size='4' face='Arial'>Continue</font></a></font></u><font size='4' face='Arial'><br> </font></p>"; $OK = 1; } if(!$_POST['over_18']){ echo "<p><br> <font size='4'face='Arial'>You must be a legal adult, over 18, to participate in our programs. <br> Please reapply when you are of legal age, 18 and over.</font></p>"; } if(!$_POST['incomesource']){ echo "<p><br> <font size='4' face='Arial'>You must be currently employed or have a reliable source of income to participate in our programs. <br> In order to maintain good financial health, you must have an income that will enable you to keep up with your<br> financial obligations.</font></p>"; } if(!$_POST['checkingaccount']){ echo "<p><font size='4' face='Arial'>You must have an active checking account to participate in our programs. When dealing with lenders, <br> you must be able to prove that you can effectively handle your finances. A checking account shows financial stability. You can open a free checking account with $20 or less at Washington Mutual Bank.<br> </font></p>"; } if(!$_POST['savingsaccount']){ echo "<p><font size='4' face='Arial'>You must have an open savings account to participate in our programs. <br> A large part of our program is tailored towards strategic saving techniques.</font></p>"; } if(!$_POST['legalservices']){ echo "<p><font face='Arial' size='4'>You must have a legal services plan to participate in our programs. <br> Because these programs deal with using your legal rights, it is very <br> important to have your own attorney by your side.</font></p>"; } if(!$_POST['idt']){ echo "<p><font face='Arial' size='4'>You must have an identity theft protection plan to participate in our<br> programs. It is important to have protection in place for your credit as <br> well as your financial identity, as you go through this process.</font></p>"; } if(!$_POST['compaccess'] || !$_POST['inetaccess']){ echo "<p><font face='Arial' size='4'>You must have access to a computer with internet access to participate in <br> our programs. These programs are website-based and require access to the internet. <br> Your local library may provide free computer usage for it’s members.</font></p>"; } if(!$_POST['refer']){ echo "<p><font size='4' face='Arial'>In order to participate in these programs you must agree to refer at least 3<br> people into the program that also become members. The programs are FREE because <br> the CreditCoachâ„¢ Team wants to help as many people as possible and we want our <br> participants to want to help others as well.</font></p>"; } if(!$_POST['oneyear']){ echo "<p><font face='Arial' size='4'>Each member must commit to a one (1) year membership in order to <br> participate in our programs. The CreditCoachâ„¢ system is made up of <br> three distinct programs, which take some time to complete. This program <br> may not be the right fit for those who want a quick fix. It is designed to <br> assist those who are willing to make a commitment to developing a healthy financial future.</font></p>"; } if(!$_POST['lessons']){ echo "<p><font face='Arial' size='4'>In order to participate in these programs you must commit to doing the <br> tutorials, lessons and projects required. This program is designed to <br> assist others, but only if they are willing to help themselves. If you <br> are unwilling to do the work, this program is not for you.</font></p>"; } if(!$_POST['iagree']){ echo "<p><font face='Arial' size='4'>You <u>must</u> agree to the terms and conditions to become a member.</font></p>"; } //Continue to registration if((!$_POST['checkingaccount'] || !$_POST['savingsaccount'] || !$_POST['legalservices'] || !$_POST['idt'] || !$_POST['compaccess'] || !$_POST['inetaccess']) && ($_POST['over_18'] && $_POST['incomesource'] && $_POST['refer'] && $_POST['oneyear'] && $_POST['lessons'])){ echo "<p align='left'><u><font color='#FF0000'> <a href='http://www.youronlinecreditcoach.com/register.php'> <font color='#FF0000' size='4' face='Arial'>Continue</font></a></font></u><font size='4' face='Arial'><br> </font></p>"; } /* Add the new account to the database */ $_SESSION['reguname'] = $_POST['name']; $_SESSION['regresult'] = addNewUser($_POST['name'], $_POST['phone'], $_POST['email'], $_POST['state'], $_POST['city'], $_POST['address'], $_POST['address2'], $_POST['referredby'], $date); $_SESSION['registered'] = true; echo "<meta http-equiv=\"Refresh\" url=$HTTP_SERVER_VARS[PHP_SELF]\">"; return; } ?> And I know for a fact that the input feilds are correctly named. Thanx
Hi I suspect that you are not checking the posted data correctly: if(!$_POST['over_18']){ echo "<p><br> <font size='4'face='Arial'>You must be a legal adult, over 18, to participate in our programs. <br> Please reapply when you are of legal age, 18 and over.</font></p>"; } PHP: Should be something like if ( isset($_POST['over_18']) && $_POST['over_18'] != '1' ) { echo "<p><br> <font size='4'face='Arial'>You must be a legal adult, over 18, to participate in our programs. <br> Please reapply when you are of legal age, 18 and over.</font></p>"; } PHP: You will need to change the if statement to check for whatever data you are expecting Brew
Thanx for the qiuck reply. I used !isset($_POST[whatever]) ,but still won't submit. here's the new style. <? session_start(); include("database.php"); $date = date("Y/m/d"); //see if name already exists in database function Name_Exists($Name){ global $conn; if(!get_magic_quotes_gpc()){ $Name = addslashes($Name); } $q = "select Name from members where Name = '$Name'"; $result = mysql_query($q,$conn); return (mysql_numrows($result) > 0); } /** * Inserts the given * into the database. Returns true on success, * false otherwise. */ function addNewUser($Name, $Phone, $Email, $State, $City, $Address, $Address2, $Referredby, $date){ global $conn; $q = "INSERT INTO members VALUES ('$Name', '$Phone', '$Email' , '$State' , '$City' , '$Address' , '$Address2' , '$Referredby', '$date')"; return mysql_query($q,$conn); } /** * Determines whether or not to show to sign-up form * based on whether the form has been submitted, if it * has, check the database for consistency and create * the new account. */ if(isset($_POST['submit'])){ /* Make sure all fields were entered */ if(!$_POST['name'] || !$_POST['phone'] || !$_POST['email'] || !$_POST['state'] || !$_POST['city'] || !$_POST['address']){ die('You didn\'t fill in a required field.'); } /* Spruce up username, check length */ $_POST['name'] = trim($_POST['name']); $_POST['phone'] = trim($_POST['phone']); $_POST['email'] = trim($_POST['email']); $_POST['state'] = trim($_POST['state']); $_POST['city'] = trim($_POST['city']); $_POST['address'] = trim($_POST['address']); $_POST['address2'] = trim($_POST['address2']); $_POST['referredby'] = trim($_POST['referredby']); if(Name_Exists($_POST['name'])){ $use = $_POST['name']; die("Sorry, the name: <strong>$use</strong> already exists in our records."); } $OK = 0; if(!isset($_POST['over_18']) || !isset($_POST['incomesource']) || !isset($_POST['checkingaccount']) || !isset($_POST['savingsaccount']) || !isset($_POST['legalservices']) || !isset($_POST['idt']) || !isset($_POST['compaccess']) || !isset($_POST['inetaccess']) || !isset($_POST['refer']) || !isset($_POST['oneyear']) || !isset($_POST['lessons']) || !isset($_POST['iagree'])){ echo "<p> </p> <p> </p> <p> </p> <img src='coach2 update copy.jpg' align='top' border='0' width='71' height='88' style='position:absolute;left:20px;top:3px;width:71px;height:88px;z-index:'> <div style='position:absolute;left:110px;top:12px;width:324px;height:55px;z-index:' align='left'> <font style='font-size:48px' color='#000000' face='Eras Demi ITC'><b>CreditCoach</font><font style='font-size:24px' color='#000000' face='Eras Demi ITC'></b>™</font></div> <div style='position:absolute;left:64px;top:56px;width:409px;height:33px;z-index:' align='center'> <font style='font-size:21px' color='#000000' face='Papyrus'><b>We help you reach financial success</b></font></div>"; $OK = 1; } else{ echo "<p> </p> <p> </p> <p> </p> <img src='coach2 update copy.jpg' align='top' border='0' width='71' height='88' style='position:absolute;left:20px;top:3px;width:71px;height:88px;z-index:'> <div style='position:absolute;left:110px;top:12px;width:324px;height:55px;z-index:' align='left'> <font style='font-size:48px' color='#000000' face='Eras Demi ITC'><b>CreditCoach</font><font style='font-size:24px' color='#000000' face='Eras Demi ITC'></b>™</font></div> <div style='position:absolute;left:64px;top:56px;width:409px;height:33px;z-index:' align='center'> <font style='font-size:21px' color='#000000' face='Papyrus'><b>We help you reach financial success</b></font></div> <p> </p><p align='left'><u><font color='#FF0000'> <a href='http://www.youronlinecreditcoach.com/register.php'> <font color='#FF0000' size='4' face='Arial'>Continue</font></a></font></u><font size='4' face='Arial'><br> </font></p>"; $OK = 1; } if(!isset($_POST['over_18'])){ echo "<p><br> <font size='4'face='Arial'>You must be a legal adult, over 18, to participate in our programs. <br> Please reapply when you are of legal age, 18 and over.</font></p>"; } if(!isset($_POST['incomesource'])){ echo "<p><br> <font size='4' face='Arial'>You must be currently employed or have a reliable source of income to participate in our programs. <br> In order to maintain good financial health, you must have an income that will enable you to keep up with your<br> financial obligations.</font></p>"; } if(!isset($_POST['checkingaccount'])){ echo "<p><font size='4' face='Arial'>You must have an active checking account to participate in our programs. When dealing with lenders, <br> you must be able to prove that you can effectively handle your finances. A checking account shows financial stability. You can open a free checking account with $20 or less at Washington Mutual Bank.<br> </font></p>"; } if(!isset($_POST['savingsaccount'])){ echo "<p><font size='4' face='Arial'>You must have an open savings account to participate in our programs. <br> A large part of our program is tailored towards strategic saving techniques.</font></p>"; } if(!isset($_POST['legalservices'])){ echo "<p><font face='Arial' size='4'>You must have a legal services plan to participate in our programs. <br> Because these programs deal with using your legal rights, it is very <br> important to have your own attorney by your side.</font></p>"; } if(!isset($_POST['idt'])){ echo "<p><font face='Arial' size='4'>You must have an identity theft protection plan to participate in our<br> programs. It is important to have protection in place for your credit as <br> well as your financial identity, as you go through this process.</font></p>"; } if(!isset($_POST['compaccess']) || !isset($_POST['inetaccess'])){ echo "<p><font face='Arial' size='4'>You must have access to a computer with internet access to participate in <br> our programs. These programs are website-based and require access to the internet. <br> Your local library may provide free computer usage for it’s members.</font></p>"; } if(!isset($_POST['refer'])){ echo "<p><font size='4' face='Arial'>In order to participate in these programs you must agree to refer at least 3<br> people into the program that also become members. The programs are FREE because <br> the CreditCoachâ„¢ Team wants to help as many people as possible and we want our <br> participants to want to help others as well.</font></p>"; } if(!isset($_POST['oneyear'])){ echo "<p><font face='Arial' size='4'>Each member must commit to a one (1) year membership in order to <br> participate in our programs. The CreditCoachâ„¢ system is made up of <br> three distinct programs, which take some time to complete. This program <br> may not be the right fit for those who want a quick fix. It is designed to <br> assist those who are willing to make a commitment to developing a healthy financial future.</font></p>"; } if(!isset($_POST['lessons'])){ echo "<p><font face='Arial' size='4'>In order to participate in these programs you must commit to doing the <br> tutorials, lessons and projects required. This program is designed to <br> assist others, but only if they are willing to help themselves. If you <br> are unwilling to do the work, this program is not for you.</font></p>"; } if(!isset($_POST['iagree'])){ echo "<p><font face='Arial' size='4'>You <u>must</u> agree to the terms and conditions to become a member.</font></p>"; } //Continue to registration if(!isset($_POST['checkingaccount']) || !isset($_POST['savingsaccount']) || !isset($_POST['legalservices']) || !isset($_POST['idt']) || !isset($_POST['compaccess']) || !isset($_POST['inetaccess']) && isset($_POST['over_18']) && isset($_POST['incomesource']) && isset($_POST['refer']) && isset($_POST['oneyear']) && isset($_POST['lessons'])){ echo "<p align='left'><u><font color='#FF0000'> <a href='http://www.youronlinecreditcoach.com/register.php'> <font color='#FF0000' size='4' face='Arial'>Continue</font></a></font></u><font size='4' face='Arial'><br> </font></p>"; } /* Add the new account to the database */ $_SESSION['reguname'] = $_POST['name']; $_SESSION['OK'] = addNewUser($_POST['name'], $_POST['phone'], $_POST['email'], $_POST['state'], $_POST['city'], $_POST['address'], $_POST['address2'], $_POST['referredby'], $date); $_SESSION['registered'] = true; echo "<meta http-equiv=\"Refresh\" url=$HTTP_SERVER_VARS[PHP_SELF]\">"; return; } ?> Code (markup):
Here's the link the page. It has too many characters to post here. http://www.youronlinecreditcoach.com/QualifyingQuestionnaire.php
Try something like this: if ( isset($_POST['over_18']) && strtoupper($_POST['over_18']) != 'Y' ) { echo "<p><br> <font size='4'face='Arial'>You must be a legal adult, over 18, to participate in our programs. <br> Please reapply when you are of legal age, 18 and over.</font></p>"; } PHP: There are no checkboxes in the form - they are all text boxes Brew
oops forgot a character here's the right page. http://www.youronlinecreditcoach.com/QualifyingQuestionnaire2.php
OK, but my last code should still work - change your checkbox checking code to what I have suggested and tell me what fails after that. One other thing, the code is full of depreciated font tags which are severly bloating the html. The code also fails to validate: http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fwww.youronlinecreditcoach.com%2FQualifyingQuestionnaire2.php Brew
Okay I tried that out, but it's still doing the same thing. It echoes the proper message and does not send the text input field data to the DB.
Sorry, it got a bit late for me last night. This code should work : if ( $_POST['over_18'] != 'Y' ) { echo "<p><br> <font size='4'face='Arial'>You must be a legal adult, over 18, to participate in our programs. <br> Please reapply when you are of legal age, 18 and over.</font></p>"; } PHP: Brew
Hi, I figured out the problem. It won't submit because I added an extra column to the table it's submitting to. Duh! Thanks alot for tour help!