Jump to content

code not executing help


paulmo

Recommended Posts

this form code was executing/printing fine before i started the if/elseif statements near the bottom. getting the whitespace/variable t errors but i'm guessing something else is wrong...need to have if/ifelse statements dependent on the 'theme' selections of a radio field, on the html form.

 

<?php
//Check whether the form has been submitted
if (array_key_exists('check_submit', $_POST)){
   //Converts the new line characters (\n) in the text area 

into HTML line breaks (the <br /> tag)
   $_POST['Comments'] = nl2br($_POST['Comments']); 
   //Check whether a $_GET['Languages'] is set
   if ( isset($_POST['Colors']) ) { 
     $_POST['Colors'] = implode(', ', $_POST['Colors']); 

//Converts an array into a single string
   }

   //Let's now print out the received values in the browser

if ($theme == black) {
echo "Dark day,($_POST['Name'])";
} elseif ($theme == light) {
echo "Lightness prevails,($_POST['Name'])";
}elseif ($theme == grey) { 
echo "Somber day,($_POST['Name'])";
} else {
echo "Please choose a value.";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/93863-code-not-executing-help/
Share on other sites

First thing I noticed is that you need black light grey in quotes so it can compare it.

 

<?php
if ($theme == 'black') {
echo "Dark day,($_POST['Name'])";
} elseif ($theme == 'light') {
echo "Lightness prevails,($_POST['Name'])";
}elseif ($theme == 'grey') { 
echo "Somber day,($_POST['Name'])";
} else {
echo "Please choose a value.";
}
?>

copy/pasted again. at least not getting parse/variable t errors now...it's going to the proper page, which is named process.php. the html form is in a separate page; this is the form, whose radio buttons aren't selecting. (they were selecting previously until i deleted some code in the form, and when i got to process.php page the "please choose a value" was printing, which meant that radio selections weren't working anyway, just defaulting):

<form action="process.php" method="post"> 
First Name<input type="text" name="Name"><br>
<input type="radio" theme="grey">grey<br>
<input type="radio" theme="black">black<br> 
<input type="radio" theme="light">light<br>
<input type="submit" value="Process"> 
</form>

 

 

Archived

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

×
×
  • 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.