Jump to content

Archived

This topic is now archived and is closed to further replies.

Eugene

Why does this happen?

Recommended Posts

[code]if($qqq == $uuu) {
    echo "<tr>
    <td>&nbsp;</td>
    <td valign=\"768\">
    <div class=\"tableborder\">
    <div class=\"maintitle\">Confirmation</div>
    <form method=\"post\">
    Are you sure you want to delete: <b>$ttt</b>?<br><br>
    <input type=\"submit\" name=\"iii\" value=\"Delete\">
    </form>";
        if($_POST['iii']) {    
        echo "Hi";
        }
        if(!$_POST['iii']) {
        echo "Bye";
        }
    }

    if($qqq != $uuu) {
    echo "<tr>
    <td>&nbsp;</td>
    <td valign=\"768\">
    <div class=\"tableborder\">
    <div class=\"maintitle\">Error</div>
    We're Sorry, but we cannot find that users ID in our Database
    </div>
    </td>";
    }[/code]

There's the code. Everything looks right. Right?

Anyway when I go to the page, it echos the "Bye" Next to the delete button which the name is iii and I didn't even submit it!

Share this post


Link to post
Share on other sites
I believe the problem is with this snippet:

if($_POST['iii']) {
echo "Hi";
}
if(!$_POST['iii']) {
echo "Bye";

the second if will always be true the way it is written, I think...
either way, do it like this, Bye will only display if $_POST['iii'] doesn't exist that way...

if(isset($_POST['iii'])) {
echo "Hi";
}
else {
echo "Bye";}

Share this post


Link to post
Share on other sites
[a href=\"http://imageshack.us\" target=\"_blank\"][img src=\"http://img143.imageshack.us/img143/7199/conf2zf.png\" border=\"0\" alt=\"IPB Image\" /][/a]

Still :(

Share this post


Link to post
Share on other sites
What are you trying to do? Becuase that is the correct result your getting with the following codet:
[code] if(isset($_POST['iii'])) {
echo "Hi";
}
else {
  echo "Bye";
}[/code]
Because what the above code does is check whether $_POST['iii'] is set, if it is it'll echo out [b]Hi[/b], otherwise if $_POST['iii'] is not set it'll echo [b]Bye[/b]. This code will run with or without the Delete button being clicked.

So what are you trying to do?

Share this post


Link to post
Share on other sites
WEll the Hi, is supposed to be the code that deleted the specified user. Bye is just a test to see if the submit button is working, obviously not.

Share this post


Link to post
Share on other sites
So you want to disply Hi instead of Bye?

I dont get what you are trying to do. PHP is not like Javascript you know where you click say a link and the text in the certain div changes to something else. PHP is completly different the code will only run when you request a page, ie when you submit a form or click a link.

Can you please explain in more detail about what you are attempting to do when you click the delete button. As currently your code is working correctly as when you request a page nothing will be set in the $_POST variable until you send _POST data to one of your pages, which the $_POSt['iii'] variable will be set when you click the delete button and your form submits, untill your form submits nothing will evaluate to true in the current you are using to show Hi or Bye.

Take this example:
[code]<?php

if(isset($_GET['iii']))
{
    echo "You have clicked the link! (Hi)";
}
else
{
    echo "Oh, You havn't clicked the link. (Bye)";
}

?>
<p><a href="?iii=Delete">Click this link</a></p>[/code]That code is the same as what you have got currently but I'm using a link and submitting the data over the URL whihc is the GET method. That is currently way your script is doing. The message [i]Oh, You havn't clicked the link. (Bye)[/i] wont change until you click the link.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.