Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8379121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:05:39+00:00 2026-06-09T16:05:39+00:00

Well then, this is likely to be the n-th time someone is asking this,

  • 0

Well then, this is likely to be the n-th time someone is asking this, but honestly I didn’t grab anything useful spending the last hour or so on Google. What I want to do is rather trivia, or so I thought. I have this working in Java Script but want to move it to PHP. In brief:

  • declare a var with a static value
  • add text field into which user is asked to enter value of above var
  • check if field is a) empty, b) non-empty mismatch, or c) non-empty match

My (limited) PHP wisdom has lead me into believing it ought to be something like the below, but apparently it’s not. I’d very much appreciate any insight, tha.

<?php
$coconew = "blah";

if (isset ($_POST["cocosub"])) {
    if ($_POST["cocoval"] == "") {
        echo "empty";
    } else {
        if ($_POST["cocoval"] != $coconew) {
            echo "mismatch";
        } else {
            echo "match";
        }
    }
}
?>

<form action="<?php $_SERVER['PHP_SELF'] ?>" id="cocosub" method="post">
    <div>
        <?php echo $coconew; ?>
        <input type="text" id="cocoval">
        <input type="submit">
    </div>
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:05:40+00:00Added an answer on June 9, 2026 at 4:05 pm

    This works:

    <?php
    session_start();
    
    if(isset($_POST["cocosub"])){
    
        $input = trim($_POST["cocoval"]);
    
        if($input == ""){
            echo "empty";
        } elseif($input != $_SESSION["coconew"]){
            echo "mismatch";
        } else {
            echo "match";
        }
    }
    
    $_SESSION["coconew"] = substr(md5(uniqid()), 0, 5);
    
    ?>
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="cocosub" method="post">
    <div>
        <?php echo $_SESSION["coconew"]; ?>
        <input type="text" id="cocoval" name="cocoval">
        <input type="submit" name="cocosub">
    </div>
    </form>
    

    You needed to add name=”cocosub” to the Submit button element in order for the first if(isset(…)) condition to be true. That’s why the script didn’t work. Also, instead of id, you need to use the name=”cocoval” in the input text field as well in order for it to carry over into $_POST.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This likely isn't possible, but I thought I would ask just to be sure.
Hey Everyone. I'm a first time poster, but I've browsed this site a number
Well, it's Friday, and I just got an error message in MS-Outlook. Then it
well i have a configuration like this in the components part of my config
Well, I have a application which somehow requires some system resources, but how do
How can I use trigger to simply update a table with the last time
I have four numbers that can possible be the same, but or most likely
A dojo JsonRest will likely send something like this to the server: /FooObject/?foo=value1&sortBy=+foo,-bar I
I did do some googling and searching on this site but did not find
I came across this stackoverflow question & then to this article through that question.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.