help on code to debug

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
wtolentino
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Jun 28, 2018 10:49 am

Thu Jun 28, 2018 11:04 am

i have this small code that i am debugging for our assignment. i am very new to php and had taken a class to help me familiar with it. i managed to fix some of it but still it appears that when the button submit is clicked it supposed to be displaying the "your mood is ...". and it is not. i have been trying to debug this for weeks but couldn't find what's the error. please advise. thank you.

Code: Select all

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1); 
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Assignment 02: Bad Code</title>
    <style>
        body {
            background-color: aquamarine;
            color: #333;
            font-family: Consolas, Calibri, Arial;
            padding: 0px 20px 20px 20px;
            font-weight:bold;
            font-size:16px;
            text-align:center;
        }
        h1,h2,h3,h4 {
            color:maroon;
        }
    </style>
</head>
<body>
  <?php
   
   if (empty($_GET["mood"])){
    ?>
     <h2>Bad Code 01</h2>
	 
     <?php
	  echo "<form method='get' action='index.php'>\n";
      echo "<p>What's your mood?"
     ?>
	 
     <input id="RBAwesome" type="radio" name="mood" value="Awesome"  /> <label for="RBAwesome">Awesome</label>
     <input id="RBGood"    type="radio" name="mood" value="Good" />     <label for="RBGood">Good</label>
     <input id="RBOK"      type="radio" name="mood" value="Ok" />       <label for="RBOK">OK</label>
     <input id="RBGood"    type="radio" name="mood" value="Good" />     <label for="RBGood">Awful</label>
     </p>
	 
     <input type="button" value="submit" name="submit"/>
     <input type="reset"  value="reset" name="reset" />
	
	 
     <?php
     echo "</form>";
   } else {
     //show results
    ?>
     <p>Your mood is: 
	 <?php echo $_GET["mood"]; ?></p>
     <?php
   }
  ?>    
</body>
</html>

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 720
Joined: Mon Feb 22, 2016 5:52 pm

Thu Jun 28, 2018 12:50 pm

it supposed to be displaying the "your mood is ...". and it is not.
What does it do correctly?

What error messages are you getting?

User avatar
mrkampf
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Jun 28, 2018 10:08 pm

Thu Jun 28, 2018 10:25 pm

Hello wtolentino,

i have found your error.
You write in your code

Code: Select all

<input type="button" value="submit" name="submit"/>
you want to send this with button submit button. Because you dont must be use type "button" use instead type "submit" and then it's work.

Sorry for my bad english, it's not perfect :D.

When you have questions or other problems write this and i tries help you.
Have a nice day.

greeting,
MrKampf

wtolentino
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Jun 28, 2018 10:49 am

Fri Jun 29, 2018 3:45 am

i tried any of this and still does not work

Code: Select all

<input type="submit" value="button" name="submit"/>

Code: Select all

<input type="button" value="button" name="submit"/>

User avatar
mrkampf
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Jun 28, 2018 10:08 pm

Fri Jun 29, 2018 4:26 am

Code: Select all

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Assignment 02: Bad Code</title>
    <style>
        body {
            background-color: aquamarine;
            color: #333;
            font-family: Consolas, Calibri, Arial;
            padding: 0px 20px 20px 20px;
            font-weight:bold;
            font-size:16px;
            text-align:center;
        }
        h1,h2,h3,h4 {
            color:maroon;
        }
    </style>
</head>
<body>
<?php

if (empty($_GET["mood"])){
    ?>
    <h2>Bad Code 01</h2>

    <form method='get' action='index.php'>
    <p>What's your mood?

    <input id="RBAwesome" type="radio" name="mood" value="Awesome"  /> <label for="RBAwesome">Awesome</label>
    <input id="RBGood"    type="radio" name="mood" value="Good" />     <label for="RBGood">Good</label>
    <input id="RBOK"      type="radio" name="mood" value="Ok" />       <label for="RBOK">OK</label>
    <input id="RBGood"    type="radio" name="mood" value="Good" />     <label for="RBGood">Awful</label>
    </p>

    <input type="submit" value="submit" name="submit"/>
    <input type="reset"  value="reset" name="reset" />


    <?php
    echo "</form>";
} else {
    //show results
    ?>
    <p>Your mood is:
        <?php echo $_GET["mood"]; ?></p>
    <?php
}
?>
</body>
</html>
Copy this code, i have test this now on xampp and two webserver and it's work.

wtolentino
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Jun 28, 2018 10:49 am

Fri Jun 29, 2018 5:19 am

it works thanks so much.

Post Reply