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 7546425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:11:40+00:00 2026-05-30T09:11:40+00:00

I am trying to do some error checking. I want to make it so

  • 0

I am trying to do some error checking. I want to make it so that if no radio button is checked on an html page, it will pass to the php and tell the user to choose a radio button and a link to go back to that page.

Included is my current code:

PHP

<?php


switch($_POST["city"]){
    case "sf":
        echo "Welcome to San Francisco, enjoy the beautiful weather.";
        break;
    case "tokyo":
        echo "Welcome to Tokyo, enjoy the sushi.";
        break;
    case "paris";
        echo "Welcome to Paris, enjoy the Eiffel Tower.";
        break;
    Default:
        echo "Please pick a city.";
        echo "<a href=\"/week7.html\">Go Back</a>";


}

?>

HTML

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <div>
            <form action="Week7PHP.php" method="post">
                <input type="radio" name="city" value="sf">San Francisco<br />
                <input type="radio" name="city" value="paris">Paris<br/>
                <input type="radio" name="city" value="tokyo">Tokyo<br/>
                <input type="submit" id="Submit">
            </form>
        </div>
    </body>
</html>

It is giving an error when it isn’t finding any of the radio buttons checked.

This is the error if no option is picked: Notice: Undefined index: city

  • 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-05-30T09:11:42+00:00Added an answer on May 30, 2026 at 9:11 am

    The reason you may be getting an error is your using $_POST["city"] before it was set by posting

    I personally would not use a _POST _GET _REQUEST globals within a switch.
    I would code a controller no matter how basic the script is that checks and handles these “special” variables.

    Something as simple as:

    <?php 
    if(isset($_POST['city'])){
        $city=$_POST['city'];
    }else{
        $city='';
    }
    //Or simpler
    $city=(isset($_POST['city']))?$_POST['city']:'';
    
    
    
    //The use $city
    switch($city){
        case "sf":
            echo "Welcome to San Francisco, enjoy the beautiful weather.";
            break;
        case "tokyo":
            echo "Welcome to Tokyo, enjoy the sushi.";
            break;
        ...
        ...
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some error checking and trying to make use of an boolean array
I'm trying to add some error checking inside my PHP script. Is it valid
Some overflow runtime error happens when my C++ program is trying to write some
I got an error today while trying to do some formatting to existing code.
I keep getting this error while trying to modify some tables. Here's my code:
I'm trying to do some C++ exercises, but I'm running into a error on
I'm trying to rename some files, but getting a baffling error*. When I run
Im trying my first form validation with PHP. I need some guidance with the
I am trying to write a simple Ruby program that I will run from
I am trying to get some errors returned in JSON format. So, I made

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.