Page 1 of 1

[SOLVED] isset() in if statement problems

Posted: Tue May 27, 2008 5:22 am
by Janco
Guys,

Can someone please explain to me how isset works in a if statement?? I've read numerous posts on the Internet and read the PHP Manual and thought that I did grasp it but this piece of code does not want to play nice... (Please draw pictures because I'm going to pretend to be slow - oh I forgot don't have to pretend -)

My Form:

Code: Select all

<form method="post">
<tr><td>Full Name:</td><td><input type="text" size="15" maxlength="40" name="fname"></td></tr>
<tr><td>User Name:</td><td><input type="text" size="15" maxlength="40" name="uname"></td></tr>
<tr><td>Password :</td><td><input type="password" size="15" maxlength="40" name="passwd"></td></tr>
<tr><td><input type="submit" value="Create" name="submit"><input type="reset" value="Clear"></td></tr>
</form>
My PHP Query:

Code: Select all

<?php
 
if (isset($_POST['fname']) && isset($_POST['uname']) && isset($_POST['passwd'])) {
 
                $fname = $_POST['fname'];
                $uname = $_POST['uname'];
                $passwd = $_POST['passwd'];
} else {
                echo "<center><font=\"red\">Not All Fields Filled IN!!</font></center>";
                exit();
}
 
echo "<center><font color=\"red\">". $fname ."</font></center>";
echo $uname;
echo $passwd;
 
?>
The strange thing is that I have written a LOgin Page with similar code and that works and I have gone over the code several times but I can't find the problem and unfortunately there is no-one here, where I work, that can help me.

Can someone please help me?

Re: isset() in if statement problems

Posted: Tue May 27, 2008 6:32 am
by N1gel
You could check to see if the values are actually being posted.

Try putting something like this at the top of your code.

Code: Select all

print_r($_POST);
This should print everything in the POST array

Re: isset() in if statement problems

Posted: Tue May 27, 2008 6:53 am
by Janco
Nothing is displayed. It is like the "POST" is not working!?

I've opened a separate terminal and ran tail -f /etc/httpd/logs/error_logs to see if I can't pick up something there but nothing.

I've even added a fwrite() to write the variables to file in the hope that there might be something wrong/not added in my HTML Code, been there before, but alas everything in the HTML Code is as it should be.

Is there another place that I can go look for error messages, maybe a php.log or something somewhere?

Re: isset() in if statement problems

Posted: Tue May 27, 2008 7:03 am
by N1gel
Is this all in the same PHP file or do you need to use the action on the form like.

Code: Select all

<form method="post" action="submit.php">
I created a test php file (below) and it seemed to work fine at posting the values

Code: Select all

<form method="post">
<tr><td>Full Name:</td><td><input type="text" size="15" maxlength="40" name="fname"></td></tr>
<tr><td>User Name:</td><td><input type="text" size="15" maxlength="40" name="uname"></td></tr>
<tr><td>Password :</td><td><input type="password" size="15" maxlength="40" name="passwd"></td></tr>
<tr><td><input type="submit" value="Create" name="submit"><input type="reset" value="Clear"></td></tr>
</form>
 
<?php
print_r($_POST);
?>

Re: isset() in if statement problems

Posted: Tue May 27, 2008 7:28 am
by Janco
All is in the same page.

When I use

Code: Select all

<form method="post" action="test.php">
it works fine but as soon as I uncomment the code in the same page I'm back to square one.

Re: isset() in if statement problems

Posted: Tue May 27, 2008 7:53 am
by Janco
I've deleted the page and started from scratch and would you know it.....it works! The strange thing is that I used the exact same code which brings me to the conclusion that there was something wrong with the HTML Code - either an unclosed <table>, <tr> or <td> tag which caused the php section not be be read but if it wasn't that I'll never know.

Thanks for the help though!