Solved

Display text based on POST variable

Posted on 2011-09-27
2
203 Views
Last Modified: 2012-05-12
Perhaps I'm having a brain lapse but i cannot get a variable to work.  I want to post text based on what the POST variable is.  I am using the code below.

 
<?php
			// Get Quarter to show report selected 
			
			if($_POST['qSelect'] = '1') { $quart = "First Quarter"; }
			elseif($_POST['qSelect'] = '2') {$quart = "Second Quarter"; }
			
			?>

Open in new window


I am then using the $quart variable to display the user's choice.
0
Comment
Question by:axessJosh
2 Comments
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 250 total points
ID: 36710673
<?php
                  // Get Quarter to show report selected
                  
                  if($_POST['qSelect'] == '1') { $quart = "First Quarter"; }
                  elseif($_POST['qSelect'] == '2') {$quart = "Second Quarter"; }
                  
                  ?>
0
 
LVL 13

Expert Comment

by:haloexpertsexchange
ID: 36710692
rik is right, your problem is the = you used in the if statement, instead of the ==. Remember in php = is for assigning values to a variable, == is for comparison. So what you are doing in the if statement is assigning first 1 to $_POST['qSelect'] then assigning it 2 instead of checking the values.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question