Jump to content

[SOLVED] can't get the elseif statement to work for me


suttercain

Recommended Posts

Hi guys,

 

I am running the following code:

<?php
//voting system
		  
		  if ($vbulletin->userinfo['usergroupid'] == '6' || 
		  	  $vbulletin->userinfo['usergroupid'] == '9' && 
			  !isset($_POST['submit'])) { 
			  
		  voteNow();
		  } 
		  elseif (isset($_POST['submit'])) {
				  echo "Thank you for voting!";
		  } else {
		  		  echo "Please Login to vote"; }
		  
		  
		  function voteNow() {
		  ?>
		  	<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
			     <select>
				 	<option>5</option>
					<option>4</option>
					<option>3</option>
					<option>2</option>
					<option>1</option>
				</select>
		  		<input type="submit" name="submit" value="Vote">
				</form>
		  <?php } ?>

 

I have a small form. If the submit button has not been pressed, it echos the form.

 

I can't get it to not echo the form if the submit button has been pressed though...

 

Do I have it set up wrong?

 

Thanks

U r using

action="<?php $_SERVER['PHP_SELF'] ?>"

it mean that it process the from in sam page,

Then how it possible that without redirect u will not see the same page.

 

Bcoz when u submit the form, code process on the same page then difenetly it

will show u the page agian.

 

For this issue just redirect the whole page then give the back button using js or something

To come back to prev page.

 

 

Got it working, here is how I did it in case this helps someone else in the future:

 

if ($vbulletin->userinfo['usergroupid'] == '1' || 
		  	  $vbulletin->userinfo['usergroupid'] == '9') {
			  if (!isset($_POST['submit'])) { 
			  	voteNow();
		  		} else {
		  		voted ();
		  		}
			} else {
			echo "Login to Vote";
				}
		  
		  
		  function voteNow() {
		  ?>
		  	<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
			     <select>
				 	<option>5</option>
					<option>4</option>
					<option>3</option>
					<option>2</option>
					<option>1</option>
				</select>
		  		<input type="submit" name="submit" value="Vote">
				</form>
		  <?php } 
		  
		  function voted() {
		  echo "Thank you for voting!"; }
		  ?>

 

Processes the form without leaving the page and based on the if statement echoes the desired statement or function.

 

Peace

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.