Jump to content

If..Else on submit problem


IceDragon

Recommended Posts

I want to make a textbox in which you would have to type in a certain word to be redirected to some other website after submiting.. but i can't figure out why it is not working..  If I upload this the page just keeps refreshing.

 

 

here's the code

<?php
    
include "wrong.php";

  $answer=TEST;
  if(isset($answer['submit']))
{
  if($answer==TEST)
  {
    print '<META HTTP-EQUIV="Refresh" Content="0; URL=http://somewebsite.com';    
   exit;
  }
  else
  {
    print "$wrong<br>";
  }
}
else
{
  print "<form action='index.php' method='post'>";
  print "<p align='center'>Answer:<br></p>";
  print "<p align='center'><input type='text' name='answer' size='30'><br></p>";
  print "<p align='center'><input type='submit' name='submit' align='center' value='Send'></form></p>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/119897-ifelse-on-submit-problem/
Share on other sites

you only need 1 equal sign to set a variable. while comparing 2 variables, you have to use 2.

 

this is the right code"

 

<?php
    
include "wrong.php";

  $answer= "TEST";
  if(isset($answer['submit']))
{
  if($answer=="TEST")
  {
    print '<META HTTP-EQUIV="Refresh" Content="0; URL=http://somewebsite.com">';    
   exit;
  }
  else
  {
    print "$wrong<br>";
  }
}
else
{
  print "<form action='index.php' method='post'>";
  print "<p align='center'>Answer:<br></p>";
  print "<p align='center'><input type='text' name='answer' size='30'><br></p>";
  print "<p align='center'><input type='submit' name='submit' align='center' value='Send'></form></p>";
}
?>

you only need 1 equal sign to set a variable. while comparing 2 variables, you have to use 2.

 

this is the right code"

 

 

EDIT: you never set $answer['submit']

its set in this now...

 

<?php
    
include "wrong.php";
$answer['submit'] ="go";
  $answer= "TEST";
  if(isset($answer['submit']))
{
  if($answer=="TEST")
  {
    print '<META HTTP-EQUIV="Refresh" Content="0; URL=http://somewebsite.com">';    
   exit;
  }
  else
  {
    print "$wrong<br>";
  }
}
else
{
  print "<form action='index.php' method='post'>";
  print "<p align='center'>Answer:<br></p>";
  print "<p align='center'><input type='text' name='answer' size='30'><br></p>";
  print "<p align='center'><input type='submit' name='submit' align='center' value='Send'></form></p>";
}
?>

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.