Jump to content

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!
Link to comment
https://forums.phpfreaks.com/topic/7406-why-does-this-happen/
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";}
Link to comment
https://forums.phpfreaks.com/topic/7406-why-does-this-happen/#findComment-26962
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?
Link to comment
https://forums.phpfreaks.com/topic/7406-why-does-this-happen/#findComment-26977
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.
Link to comment
https://forums.phpfreaks.com/topic/7406-why-does-this-happen/#findComment-26990
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.