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
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.";
}
?>

Link to comment
Share on other sites

Try this:

 

<?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.";
}
?>

Link to comment
Share on other sites

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>

 

 

Link to comment
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.