[SOLVED] isset() in if statement problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Janco
Forum Commoner
Posts: 37
Joined: Fri Apr 25, 2008 2:51 am

[SOLVED] isset() in if statement problems

Post 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?
Last edited by Janco on Tue May 27, 2008 7:54 am, edited 1 time in total.
User avatar
N1gel
Forum Commoner
Posts: 95
Joined: Sun Apr 30, 2006 12:01 pm

Re: isset() in if statement problems

Post 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
Janco
Forum Commoner
Posts: 37
Joined: Fri Apr 25, 2008 2:51 am

Re: isset() in if statement problems

Post 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?
User avatar
N1gel
Forum Commoner
Posts: 95
Joined: Sun Apr 30, 2006 12:01 pm

Re: isset() in if statement problems

Post 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);
?>
Janco
Forum Commoner
Posts: 37
Joined: Fri Apr 25, 2008 2:51 am

Re: isset() in if statement problems

Post 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.
Janco
Forum Commoner
Posts: 37
Joined: Fri Apr 25, 2008 2:51 am

Re: isset() in if statement problems

Post 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!
Post Reply