ukweb Posted May 29, 2006 Share Posted May 29, 2006 HiI'm making a registration system for a clients website. On the first page is a form with elements called 'email' and 'password'.On the following page if a username or password has not been set it should come up with a prompt for the username and password again, but it's not. Here is the bit of code I'm havin problems with;<?php if ( !isset( $_POST['email'] ) ) { ?>you did not specify a email address<?php } ?>I can;t see why its not working. If the username field is blank, surely it isnt set? or does the blank field being submitted class as being 'set'?Any suggestions around this?Many thanksSteve Quote Link to comment https://forums.phpfreaks.com/topic/10697-string-not-working-although-i-cant-see-why-not/ Share on other sites More sharing options...
samshel Posted May 29, 2006 Share Posted May 29, 2006 You are correct ..if it is blank it is not set..the problem might be somewhere else..can you please post the whole code ? Quote Link to comment https://forums.phpfreaks.com/topic/10697-string-not-working-although-i-cant-see-why-not/#findComment-39916 Share on other sites More sharing options...
AndyB Posted May 29, 2006 Share Posted May 29, 2006 email might well be not set if your form asks for username and password. Is there more code we're not seeing? Quote Link to comment https://forums.phpfreaks.com/topic/10697-string-not-working-although-i-cant-see-why-not/#findComment-39924 Share on other sites More sharing options...
kenrbnsn Posted May 29, 2006 Share Posted May 29, 2006 When a form is submitted, all text fields are set whether or not they are blank. In order to check that there is something in the value, you should check that the value is non-blank (or issue an error if it is blank).The following code illustrates this:[code]<?php if (isset($_POST['submit'])) echo '<pre>' . print_r($_POST,true) . '</pre>';?><html><head> <title>Test Form</title></head><body><?php$tmp = array();if (isset($_POST['submit'])) { if (!isset($_POST['username'])) $tmp[] = '<span style="font-weight:bold;color:red;">username</span> is not set'; if (!isset($_POST['password'])) $tmp[] = '<span style="font-weight:bold;color:red;">password</span> is not set'; if (!isset($_POST['email'])) $tmp[] = '<span style="font-weight:bold;color:red;">email</span> is not set'; foreach($_POST as $k=>$v) if ($k != 'submit') if (trim(stripslashes($v)) == '') $tmp[] = '<span style="font-weight:bold;color:blue;">' . $k . '</span> is blank'; if (!empty($tmp)) echo implode("<br>\n",$tmp)."<br>\n";}?><form method="post">Username: <input name="username" type="text"><br>Password: <input name="password" type="password"><br>Email: <input name="email" type="text"><br><input type="submit" name="submit" value="Test Form"></form></body></html>[/code]You can run this example at [a href=\"http://www.rbnsn.com/phpfreaks/test_form1.php\" target=\"_blank\"]http://www.rbnsn.com/phpfreaks/test_form1.php[/a]Whenever you have a question about what values are being returned to your script from a form, you should put the following code at the start of your script:[code]<?php if (isset($_POST['submit'])) echo '<pre>' . print_r($_POST,true) . '</pre>'; ?>[/code]This will show you the contents of the $_POST superglobal array formatted nicely.Ken Quote Link to comment https://forums.phpfreaks.com/topic/10697-string-not-working-although-i-cant-see-why-not/#findComment-39935 Share on other sites More sharing options...
ukweb Posted May 29, 2006 Author Share Posted May 29, 2006 <?phpif(!isset($tfm_rows) || intval($tfm_rows) == 0){$tfm_rows = -1;}if(!isset($tfm_columns) || intval($tfm_columns) == 0){$tfm_columns = 6;}if(!isset($tfm_vertical)){$tfm_vertical = "false";}if(!isset($tfm_rows) || intval($tfm_rows) == 0){$tfm_rows = -1;}if(!isset($tfm_columns) || intval($tfm_columns) == 0){$tfm_columns = 5;}if(!isset($tfm_vertical)){$tfm_vertical = "false";}?><?php require_once('../Connections/ukweb.php'); ?><?php require_once('../Connections/servewaldb.php'); ?><?phpif (isset($_GET['package'])) {setcookie("package", $_GET['package'], time()+86400*1);}if (isset($_GET['login_return'])) {setcookie("login_return", $_GET['login_return'], time()+86400*1);}$varpro_nav = "-1";if (isset($row_content['Profile'])) { $varpro_nav = (get_magic_quotes_gpc()) ? $row_content['Profile'] : addslashes($row_content['Profile']);}mysql_select_db($database_ukweb, $ukweb);$query_nav = sprintf("SELECT * FROM navigation WHERE Profile = '%s' ORDER BY ID DESC", $varpro_nav);$nav = mysql_query($query_nav, $ukweb) or die(mysql_error());$row_nav = mysql_fetch_assoc($nav);$totalRows_nav = mysql_num_rows($nav);$colname_checkreg = "-1";if (isset($_POST['email'])) { $colname_checkreg = (get_magic_quotes_gpc()) ? $_POST['email'] : addslashes($_POST['email']);}mysql_select_db($database_servewaldb, $servewaldb);$query_checkreg = sprintf("SELECT * FROM users WHERE email = '%s'", $colname_checkreg);$checkreg = mysql_query($query_checkreg, $servewaldb) or die(mysql_error());$row_checkreg = mysql_fetch_assoc($checkreg);$totalRows_checkreg = mysql_num_rows($checkreg);$HLoop_nav = array();$HLoop_nav_rows = $tfm_rows;$HLoop_nav_columns = $tfm_columns;$HLoop_nav_vertical = $tfm_vertical;if($HLoop_nav_vertical == "true") { $HLoop_nav_loopTo = $HLoop_nav_rows;}else{ $HLoop_nav_loopTo = $HLoop_nav_columns;}$HLoop_nav_i = 0;$HLoop_nav_ii = 0;$HLoop_nav_actualrows = 1;?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Register or Login</title><link href="../css/default.css" rel="stylesheet" type="text/css" /><link href="../css/forms.css" rel="stylesheet" type="text/css" /><script type="text/JavaScript"><!--function MM_goToURL() { //v3.0 var i, args=MM_goToURL.arguments; document.MM_returnValue = false; for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");}//--></script></head><body><div align="center"> <table width="780" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="780" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="../images/layout/tools/spacer.gif" width="100%" height="5" /></td> </tr> <tr> <td><table width="780" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="85"><img src="../images/layout/tools/nav.jpg" width="85" height="25" /></td> <td width="695" background="../images/layout/tools/barback.jpg" class="edit_commandtext"><?php do {ob_start();?> <table width="100" border="0" cellspacing="0" cellpadding="0"> <tr> <td><div align="center" class="edit_commandtext"><a class="whlink" href="index.php?PageID=<?php echo $row_nav['Page']; ?>&<?php echo $row_nav['Variables']; ?>"><?php echo $row_nav['Title']; ?></a></div></td> </tr> </table> <?php$HLoop_nav_temp = ob_get_contents();ob_end_clean();$HLoop_nav[$HLoop_nav_i][$HLoop_nav_ii] = $HLoop_nav_temp;$HLoop_nav_ii++;if($HLoop_nav_ii >= $HLoop_nav_loopTo){ $HLoop_nav_i++; $HLoop_nav_ii = 0; $HLoop_nav_actualrows++;};} while ($row_nav = mysql_fetch_assoc($nav));if($HLoop_nav_actualrows < $HLoop_nav_rows && $HLoop_nav_vertical == "false") $HLoop_nav_rows = $HLoop_nav_actualrows;if($HLoop_nav_actualrows < $HLoop_nav_columns && $HLoop_nav_vertical == "true") $HLoop_nav_columns = $HLoop_nav_actualrows;?> <table class="hloop"> <?php for($i = 0; $i < $HLoop_nav_rows; $i++) { ?> <tr> <?php for($ii = 0; $ii < $HLoop_nav_columns; $ii++) { ?> <td><?php if($HLoop_nav_vertical == "true") { echo(isset($HLoop_nav[$ii][$i]) ? $HLoop_nav[$ii][$i] : " "); }else{ echo(isset($HLoop_nav[$i][$ii]) ? $HLoop_nav[$i][$ii] : " "); } ?></td> <?php } ?> </tr> <?php } ?> </table></td> </tr> </table> </td> </tr> <tr> <td><img src="../images/layout/tools/spacer.gif" width="100%" height="5" /></td> </tr> </table></td> </tr> <tr> <td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="780" height="180"> <param name="movie" value="../flash/head.swf" /> <param name="quality" value="high" /> <embed src="../flash/head.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="780" height="180"></embed> </object></td> </tr> <tr> <td><img src="../images/layout/tools/spacer.gif" width="100%" height="5" /></td> </tr> <tr> <td><table width="780" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="575" valign="top"><table width="575" height="520" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="575" valign="top"><table width="575" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_outer"> <tr> <td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_inner"> <tr> <td><img src="../images/static/contact_r1_c1.jpg" width="80" height="16" /><img src="../images/static/contact_r1_c2.jpg" alt="Call 020 81 22 33 22" width="124" height="16" /><a href="mailto: enquiries@servewales.co.uk"><img src="../images/static/contact_r1_c3.jpg" alt="email: enquiries@servewales.co.uk" width="198" height="16" border="0" /></a></td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td valign="top"><img src="../images/layout/tools/spacer.gif" width="100%" height="5" /></td> </tr> <tr> <td valign="top"><div align="justify"> <?php if (isset( $_GET['package'] )); else if (isset( $_COOKIE['package'] )); { ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_outer"> <tr> <td><table width="100%" border="0" cellpadding="3" cellspacing="0" class="table_inner"> <tr> <td bordercolor="#FFFFFF"><img src="../images/reg/2.jpg" width="560" height="65" /></td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td><img src="../images/layout/tools/spacer.gif" width="100%" height="5" /></td> </tr> </table> <?php } ?><?php if ($totalRows_checkreg > 0) { ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_outer"> <tr> <td><table width="100%" border="0" cellpadding="3" cellspacing="0" class="table_inner"> <tr> <td bordercolor="#FFFFFF"><table width="560" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="270" valign="top"><table width="260" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><img src="../images/layout/members/register.jpg" width="135" height="18" /></td> </tr> <tr> <td><img src="../images/layout/body/spacer.gif" width="100%" height="5" /></td> </tr> <tr> <td class="text_small"><span class="error_norm">I'm afraid that email address is already registered with us</span> <br /> <br /> Please login on the right hand side or provide an alternative email address. </td> </tr> <tr> <td><img src="../images/layout/body/spacer.gif" width="100%" height="5" /></td> </tr> <tr> <td><form id="reg" name="reg" method="post" action="register.php"> <table width="260" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="130" class="text_small">Your email address: </td> <td width="130" height="21"><input name="email" type="text" class="Search_box" id="email" /></td> </tr> <tr> <td width="130" class="text_small">Password:</td> <td width="130" height="21"><input name="password" type="text" class="Search_box" id="password" /></td> </tr> <tr> <td width="130" class="text_small"> </td> <td width="130" height="25" valign="bottom"><input name="Submit22" type="submit" class="Submit_Sm" value="register" /></td> </tr> </table> </form></td> </tr> </table></td> <td width="20" valign="top"><div align="center"><img src="../images/layout/members/or.jpg" width="20" height="170" /></div></td> <td width="270" valign="top"><table width="260" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><img src="../images/layout/members/login.jpg" width="145" height="18" /></td> </tr> <tr> <td><img src="../images/layout/body/spacer.gif" width="100%" height="5" /></td> </tr> <tr> <td class="text_small"><?php if ( !($_GET['loginfail'] == "true") ) { ?> If you have an existing account, fill out the login form below to continue, using the account details you already have. <?php } ?><?php if ( ($_GET['loginfail'] == "true") ) { ?> <span class="error_norm">Login failed</span> Either your email address and/or password is incorrect <br /> <br /> <span class="error_norm">Please check and try again</span> <?php } ?></td> </tr> <tr> <td><img src="../images/layout/body/spacer.gif" width="100%" height="18" /></td> </tr> <tr> <td><form id="log" name="log" method="post" action="log_process.php"> <table width="260" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="130" class="text_small">Your email address: </td> <td width="130" height="21"><input name="email" type="text" class="Search_box" id="email" value="<?php echo $_POST['email']; ?>" /></td> </tr> <tr> <td width="130" class="text_small">Password:</td> <td width="130" height="21"><input name="password" type="password" class="Search_box" id="password" /></td> </tr> <tr> <td width="130" class="text_small"><div align="right"></div></td> <td width="130" height="25" valign="bottom"><input name="Submit2" type="submit" class="Submit_Sm" value="login" /></td> </tr> </table> </form></td> </tr> </table></td> </tr> </table></td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td><img src="../images/layout/body/spacer.gif" width="100%" height="5" /></td> </tr> <tr> <td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_outer"> <tr> <td><table width="100%" border="0" cellpadding="3" cellspacing="0" class="table_inner"> <tr> <td height="152" valign="top" bordercolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="22" valign="top"><img src="../images/layout/members/why.jpg" width="145" height="18" /></td> </tr> <tr> <td valign="top" class="text_small">Registration is mandatory process all clients must go through so we can keep track of orders, manage support tickets, and allow for site administration.</td> </tr> <tr> <td valign="top"><img src="../images/layout/tools/spacer.gif" width="100%" height="5" /></td> </tr> <tr> <td height="38" valign="top" class="text_small">It is our aim to reward loyalty, and various perks are awarded automatically through the reward scheme, which would not be humanly possible to manage without the registration system. </td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="22" valign="top"><img src="../images/layout/members/infosafe.jpg" width="160" height="18" /></td> </tr> <tr> <td valign="top" class="text_small">When you register and account with Serve Wales, your information is kept safe and will not be handed over to any 3rd party*</td> </tr> <tr> <td valign="top"><img src="../images/layout/tools/spacer.gif" width="100%" height="5" /></td> </tr> <tr> <td valign="top" class="titlesnb">What information is kept? </td> </tr> <tr> <td height="38" valign="top"><ul> <li class="text_small">Your name</li> <li class="text_small">Your contact telephone number </li> <li class="text_small">Your email address</li> <li class="text_small">Your PayPal email address </li> </ul></td> </tr> <tr> <td valign="top" class="titlesnb">What information is NOT kept under ANY circumstances? </td> </tr> <tr> <td height="38" valign="top"><ul> <li class="text_small">Your Bank details </li> <li class="text_small">Any Credit or Debit card details </li> <li class="text_small">Your PayPal Password</li> </ul></td> </tr> <tr> <td valign="top"><div align="right" class="text_smallest">* unless there is a breach of the TOS </div></td> </tr> </table></td> </tr> </table></td> </tr> </table></td> </tr> </table> <?php } ?><table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_outer"> <tr> <td><table width="100%" border="0" cellpadding="3" cellspacing="0" class="table_inner"> <tr> <td height="152" valign="top" bordercolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="22" valign="top"><img src="../images/layout/members/register.jpg" width="135" height="18" /></td> </tr> <tr> <td valign="top" class="text_small"><form id="reg2" name="reg2" method="post" action=""> <table width="558" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="4"><img src="../images/layout/body/spacer.gif" width="100%" height="4" /></td> </tr> <tr> <td colspan="4" class="text_small">Please fill out the form below to register. Registration is easy, just one page is all you need to fill out. Once you are registered, you can take advantage of the services offered by Serve Wales. <br /> <br /> The areas marked with (mandatory) are the areas where you must fill out the form information. Other areas are optional </td> </tr> <tr> <td colspan="4"><img src="../images/layout/body/spacer.gif" width="100%" height="8" /></td> </tr> <tr> <td colspan="4"><img src="../images/reg/s1.jpg" width="558" height="24" /></td> </tr> <tr> <td width="70"> </td> <td width="115" height="20">Your email: </td> <td width="140" height="20"><?php echo $_POST['email']; ?><?php if ( !isset( $_POST['email'] ) ) { ?> <input name="email" type="text" class="Reg_box" id="email" /> <?php } ?></td> <td width="233" class="text_small"><span class="error_norm"> <?php if ( !isset( $_POST['email'] ) ) { ?> You did not specify an email address <?php } ?></span></td> </tr> <tr> <td> </td> <td height="20">Your password: </td> <td height="20"><?php echo $_POST['password']; ?><?php if ( !isset( $_POST['email'] ) ) { ?> <input name="password" type="text" class="Reg_box" id="password" /> <?php } ?></td> <td class="text_small"><span class="error_norm"> <?php if ( !isset( $_POST['email'] ) ) { ?> You did not specify a password <?php } ?> </span></td> </tr> <tr> <td colspan="4"><img src="../images/layout/body/spacer.gif" width="100%" height="8" /></td> </tr> <tr> <td colspan="4"><img src="../images/reg/s2.jpg" width="558" height="24" /></td> </tr> <tr> <td> </td> <td height="22">First name: </td> <td><input name="first_name" type="text" class="Reg_box" id="first_name" /></td> <td> </td> </tr> <tr> <td> </td> <td height="22">Sirname:</td> <td><input name="sirname" type="text" class="Reg_box" id="sirname" /></td> <td> </td> </tr> <tr> <td> </td> <td height="22">Company name: </td> <td><input name="company" type="text" class="Reg_box" id="company" /></td> <td class="text_small">optional</td> </tr> <tr> <td colspan="4"><img src="../images/layout/body/spacer.gif" width="100%" height="8" /></td> </tr> <tr> <td colspan="4"><img src="../images/reg/s3.jpg" width="558" height="24" /></td> </tr> <tr> <td> </td> <td height="36">House name and number: </td> <td><input name="address1" type="text" class="Reg_box" id="address1" /></td> <td> </td> </tr> <tr> <td> </td> <td height="22">Street:</td> <td><input name="address2" type="text" class="Reg_box" id="address2" /></td> <td> </td> </tr> <tr> <td> </td> <td height="22">Town:</td> <td><input name="address3" type="text" class="Reg_box" id="address3" /></td> <td> </td> </tr> <tr> <td> </td> <td height="22">Postcode:</td> <td><input name="postcode" type="text" class="Reg_box" id="postcode" /></td> <td> </td> </tr> <tr> <td> </td> <td height="22">Phone number: </td> <td><input name="phone" type="text" class="Reg_box" id="phone" /></td> <td> </td> </tr> <tr> <td colspan="4"><img src="../images/layout/body/spacer.gif" width="100%" height="8" /></td> </tr> <tr> <td colspan="4"><img src="../images/reg/s4.jpg" width="558" height="24" /></td> </tr> <tr> <td> </td> <td height="22">Favorite food: </td> <td><input name="reminder" type="text" class="Reg_box" id="reminder" /></td> <td class="text_small">Just in case you forget your password </td> </tr> <tr> <td> </td> <td height="22">PayPal email: </td> <td><input name="paypal" type="text" class="Reg_box" id="paypal" /></td> <td class="text_small">The email account you use for PayPal </td> </tr> <tr> <td colspan="4"><img src="../images/layout/body/spacer.gif" width="100%" height="8" /></td> </tr> <tr> <td height="20" colspan="4"><img src="../images/reg/s5.jpg" width="558" height="24" /></td> </tr> <tr> <td> </td> <td height="20" colspan="3" class="text_smallest">By ticking 'I Agree' you are binding yourself to the Terms of Service (TOS) which is located here.<br /> <br /> Please note that any change to the TOS can be done at any time without prior notice, and should be regularly referred back to.</td> </tr> <tr> <td> </td> <td height="20">I Agree: </td> <td><input name="tos_agree" type="checkbox" id="tos_agree" value="True" /></td> <td> </td> </tr> <tr> <td colspan="4"><img src="../images/layout/body/spacer.gif" width="100%" height="8" /></td> </tr> <tr> <td> </td> <td><input name="Submit" type="submit" class="Submit_Sm" value="Register" /></td> <td><input name="Submit3" type="reset" class="Submit_Sm" value="Reset" /></td> <td> </td> </tr> </table> </form></td> </tr> <tr> <td valign="top"><img src="../images/layout/tools/spacer.gif" width="100%" height="5" /></td> </tr> </table></td> </tr> </table></td> </tr> </table> </div></td> </tr> </table></td> </tr> </table></td> <td width="5"><img src="../images/layout/tools/spacer.gif" width="5" height="100" /></td> <td width="200" align="center" valign="top" bgcolor="#9AC3FC" class="centre"><a href="../?PageID=58&package=2"><img src="../images/promo/foundpack.jpg" width="160" height="173" border="0" /></a><img src="../images/promo/intpack.jpg" width="160" height="173" /><img src="../images/promo/advpack.jpg" width="160" height="173" /></td> </tr> </table></td> </tr> <tr> <td><img src="../images/layout/tools/spacer.gif" width="100%" height="5" /></td> </tr> <tr> <td height="50" align="center" bgcolor="#E3E4E6" class="centre">2006 ukwebcreations | Use of Cookies | Priacy Statement | Terms of Service </td> </tr> <tr> <td align="center"><div align="left"> <table width="780" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="150" valign="top"> </td> <td width="480" height="22" valign="bottom"><div align="center"> <table width="160" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="82" valign="top">Powered by </td> <td width="78"><img src="../mysite/images/icons/design.gif" width="78" height="17" /></td> </tr> </table> </div></td> <td width="150" valign="top"> </td> </tr> </table> </div></td> </tr> </table></div></body></html><?phpmysql_free_result($nav);mysql_free_result($checkreg);?>Thats the full page code. The form which posts to this page deffinately posts text fields called email and password also. Quote Link to comment https://forums.phpfreaks.com/topic/10697-string-not-working-although-i-cant-see-why-not/#findComment-40123 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.