yona_ts Posted January 10, 2007 Share Posted January 10, 2007 hello to every one. i am making this little application in php/mysql and am facing a little problem with function isset().i have a registration form and the registration form sends the data at this php script. Take a look at the code below. [code]<?php include "config.inc.php"; include("class.FastTemplate.php3"); $con=mysql_connect($dbServer, $dbUser, $dbPass) or exit("Cannot conect to database"); if(isset($_POST["change"])){ $tpl=new FastTemplate("."); $tpl->define(array("Emp_unsuccess" => "emp_unsuccess.tpl")); $tpl->assign(array("{COMP}" =>$_POST["company"], "{ADDR}" => $_POST["address"], "{CITY}" =>$_POST["city"], "{ZIP}" =>$_POST["zip"], "{CONT}" =>$_POST["contact"], "{PHONE}" =>$_POST["phone"], "{FAX}" =>$_POST["fax"], "{MAIL}" =>$_POST["email"], "{USERNAME}"=>$_POST["user"], "{PASSWORD}"=>$_POST["password"])); if($_POST["field"]=="0"){ $tpl->assign("{FIELD}","Mathematics"); } if($_POST["field"]=="1"){ $tpl->assign("{FIELD}","Sciences"); } if($_POST["field"]=="2"){ $tpl->assign("{FIELD}","Social Sciences"); } if($_POST["field"]=="3"){ $tpl->assign("{FIELD}","Computer Sciences"); } if($_POST["field"]=="4"){ $tpl->assign("{FIELD}","History"); } if($_POST["field"]=="5"){ $tpl->assign("{FIELD}","Arts"); } if($_POST["field"]=="6"){ $tpl->assign("{FIELD}","Foreign Languages"); } if($_POST["material"]=="0"){ $tpl->assign("{FORM}",".pdf"); } if($_POST["material"]=="1"){ $tpl->assign("{FORM}",".html"); } if($_POST["material"]=="2"){ $tpl->assign("{FORM}",".exe"); } if($_POST["material"]=="3"){ $tpl->assign("{FORM}",".mp3"); } if($_POST["material"]=="4"){ $tpl->assign("{FORM}",".wma"); } if($_POST["material"]=="5"){ $tpl->assign("{FORM}",".mpeg"); } if($_POST["material"]=="6"){ $tpl->assign("{FORM}",".zip"); } $tpl->assign("{TITLE}","Registration unsuccessful"); $tpl->parse("CONTENT","Emp_unsuccess"); $tpl->FastPrint(); }?>[/code]wirthout the if statement the script is fine but as soon as i use it a blank page appears on the browser. any ideas?thnx in advance! Quote Link to comment Share on other sites More sharing options...
obsidian Posted January 10, 2007 Share Posted January 10, 2007 My guess is that the error is not with the isset() statement. Have you tried all the rest of the template code as-is? Are you positive your paths and parsing is working as intended? Quote Link to comment Share on other sites More sharing options...
taith Posted January 10, 2007 Share Posted January 10, 2007 yes... with forms, when you press submit, it sends every field as $_POST, as is, isset() will always return true, you'd want to use !empty()... Quote Link to comment Share on other sites More sharing options...
obsidian Posted January 10, 2007 Share Posted January 10, 2007 [quote author=taith link=topic=121781.msg501358#msg501358 date=1168443457]yes... with forms, when you press submit, it sends every field as $_POST, as is, isset() will always return true, you'd want to use !empty()...[/quote]Actually, isset() is the appropriate check to use to see whether or not checkboxes have been selected (and radio buttons if you don't have a default value). Also, if you're simply checking to see whether or not the form has been submitted, isset() on any of your submit, hidden, text or other default value fields would be just fine. Quote Link to comment Share on other sites More sharing options...
yona_ts Posted January 10, 2007 Author Share Posted January 10, 2007 when i remove the if(isset()) from the code and run the page with the rest of it the page appears on the browser Quote Link to comment Share on other sites More sharing options...
yona_ts Posted January 10, 2007 Author Share Posted January 10, 2007 maybe i shoud post the hole script... [code]<?php include "config.inc.php"; include("class.FastTemplate.php3"); $con=mysql_connect($dbServer, $dbUser, $dbPass) or exit("Cannot conect to database"); if(isset($_POST["change"])){ $sql1="SELECT * FROM provider WHERE provider_name='".$_POST["user"]."'"; $res1=mysql_db_query($dbDatabase,$sql1); if($res1 && mysql_num_rows($res1)) { $tpl=new FastTemplate("."); $tpl->define(array("Emp_unsuccess" => "emp_unsuccess.tpl")); $tpl->assign(array("{COMP}" =>$_POST["company"], "{ADDR}" => $_POST["address"], "{CITY}" =>$_POST["city"], "{ZIP}" =>$_POST["zip"], "{CONT}" =>$_POST["contact"], "{PHONE}" =>$_POST["phone"], "{FAX}" =>$_POST["fax"], "{MAIL}" =>$_POST["email"], "{USERNAME}"=>$_POST["user"], "{PASSWORD}"=>$_POST["password"])); if($_POST["field"]=="0"){ $tpl->assign("{FIELD}","Mathematics"); } if($_POST["field"]=="1"){ $tpl->assign("{FIELD}","Sciences"); } if($_POST["field"]=="2"){ $tpl->assign("{FIELD}","Social Sciences"); } if($_POST["field"]=="3"){ $tpl->assign("{FIELD}","Computer Sciences"); } if($_POST["field"]=="4"){ $tpl->assign("{FIELD}","History"); } if($_POST["field"]=="5"){ $tpl->assign("{FIELD}","Arts"); } if($_POST["field"]=="6"){ $tpl->assign("{FIELD}","Foreign Languages"); } if($_POST["material"]=="0"){ $tpl->assign("{FORM}",".pdf"); } if($_POST["material"]=="1"){ $tpl->assign("{FORM}",".html"); } if($_POST["material"]=="2"){ $tpl->assign("{FORM}",".exe"); } if($_POST["material"]=="3"){ $tpl->assign("{FORM}",".mp3"); } if($_POST["material"]=="4"){ $tpl->assign("{FORM}",".wma"); } if($_POST["material"]=="5"){ $tpl->assign("{FORM}",".mpeg"); } if($_POST["material"]=="6"){ $tpl->assign("{FORM}",".zip"); } $tpl->assign("{TITLE}","Registration unsuccessful"); $tpl->parse("CONTENT","Emp_unsuccess"); $tpl->FastPrint(); } else{ // insert data into provider $sql2="INSERT INTO provider VALUES ('".$_POST["user"]."', '".$POST["password"]."', '".$_POST["company"]."',. '".$_POST["field"]."', '".$_POST["material"]."', '".$_POST["address"]."', '".$_POST["city"]."', '".$_POST["zip"]."', '".$_POST["phone"]."', '".$_POST["fax"]."', '".$_POST["email"]."', '".$_POST["contact"]."')"; //----------------------------------------- $res2=mysql_db_query($dbDatabase,$sql2); $tpl=new FastTemplate("."); $tpl->define(array("Emp_success" => "emp_success.tpl")); $tpl->assign(array("{COMP}" =>$_POST["company"], "{ADDR}" => $_POST["address"], "{CITY}" =>$_POST["city"], "{ZIP}" =>$_POST["zip"], "{CONT}" =>$_POST["contact"], "{PHONE}" =>$_POST["phone"], "{FAX}" =>$_POST["fax"], "{MAIL}" =>$_POST["email"], "{FIELD}" =>$_POST["field"], "{FORM}" =>$_POST["material"], "{USERNAME}"=>$_POST["user"], "{PASSWORD}"=>$_POST["password"])); $tpl->assign("{TITLE}","Registration successful"); $tpl->parse("CONTENT","Emp_success"); $tpl->FastPrint(); } }?>[/code] Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 10, 2007 Share Posted January 10, 2007 I assume you have a form element called [i]change[/i]?I'm also a fan of single quotes rather than double quotes in the [code=php:0]$_POST['change'][/code] variables :)RegardsHuggie Quote Link to comment Share on other sites More sharing options...
taith Posted January 10, 2007 Share Posted January 10, 2007 true... isset() will check if the form was submitted, but !empty() is a much safer way of checking to see if a field has value... Quote Link to comment Share on other sites More sharing options...
yona_ts Posted January 10, 2007 Author Share Posted January 10, 2007 change is the name of the submit button Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 10, 2007 Share Posted January 10, 2007 OK, and the form method is definitely POST and not GET?Huggie Quote Link to comment Share on other sites More sharing options...
yona_ts Posted January 10, 2007 Author Share Posted January 10, 2007 yes its post and i have checked all the paths and the variables and any detail i couldthats why i tried to see if the code appears when using some parts of it... ??? Quote Link to comment Share on other sites More sharing options...
obsidian Posted January 10, 2007 Share Posted January 10, 2007 [quote author=taith link=topic=121781.msg501368#msg501368 date=1168444589]true... isset() will check if the form was submitted, but !empty() is a much safer way of checking to see if a field has value...[/quote]As I said, though, this will cause an error with any form elements that don't have a default value (keeping in mind that [b]all[/b] text fields default to an empty string). Therefore, for certain input types, if you're going to have clean code, you've got to use a balance of isset() and empty(). One is not [i]safer[/i] than the other, it's just a matter of learning to use each for which it was intended. Quote Link to comment Share on other sites More sharing options...
obsidian Posted January 10, 2007 Share Posted January 10, 2007 I think the reason you're getting a blank screen is that you process your form and everything all [b]within the submission check[/b]. Therefore, when you first hit your page, your form has not been submitted, and so nothing is displayed. You need to run your [b]processing only[/b] within the confines of your if statement. Your page should be displayed outside of those confines so that you can see the form [i]even when it hasn't been submitted yet[/i]. Quote Link to comment Share on other sites More sharing options...
yona_ts Posted January 10, 2007 Author Share Posted January 10, 2007 thnx 4 the help 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.