Jump to content

Recommended Posts

Hello PHP Freaks forum,

 

I am a beginner in web development and seem to be understanding it very quickly, but there is one thing that is putting this into some halt.

 

I have this code right here, what I want to do is have a "riddle site", where if you answer the riddle correctly, it redirects you to another page (in other words to the next riddle).

 

Object:

If correct, give access to next page.

If incorrect, stay on page and print "Incorrect".

 

I've tried to start on it, but the way how HTML and PHP don't mix very well, I feel like in the middle of an ocean feeling helpless.

 

<html>
<head>
  <title>PHP Test</title>
</head>
<body>
<p>
<font face="Courier New">ZnJ5cyBwYmFnbnZhcnEgaGFxcmVqbmdyZSBvZXJuZ3V2YXQgbmNjbmVuZ2hm</font>
</p>
CLUE: The base is rotated
<br/></body>

<form action="index-5.php" method="post">
  Answer: <input type="text" name="number" /><br />
</select>
<input name="submit" type="submit">
</form>

<?php
if(isset($_POST['submit'])){

$number = $_POST['number'];
if ($number == "scuba"){
echo "CORRECT";}
}
?>

</html>

 

 

If possible, can you give me an explanation how to do it and a sample of it as well?

 

Thanks,

Gldnbr

Link to comment
https://forums.phpfreaks.com/topic/227943-answer-correct-redirect-to-another-page/
Share on other sites

Oh okay, I see now, I didn't know you can do that.

 

But now what do you do with this?

<form action="index-5.php" method="post">

 

I need to remove that so it doesn't redirect to index-5.php when I click submit, instead it would redirect to the URL if correct.

I can't just remove it like this, can't I?

<form action="" method="post">

<form action="index-5.php" method="post">

does not redirect to the index-5.php, it simply tells the form where to submit.

 

So if your form is on the same page as your PHP script that processes it then you can use

 

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">

 

 

I am honestly confusing myself more than I should.

Why am I feeling stressed out!  The error is telling me that a header modification is already in use, I THINK.

 

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\index-4.php:12) in C:\xampp\htdocs\index-4.php on line 23

 

<html>
<head>
  <title>PHP Test</title>
</head>
<body>
<p>
<font face="Courier New">ZnJ5cyBwYmFnbnZhcnEgaGFxcmVqbmdyZSBvZXJuZ3V2YXQgbmNjbmVuZ2hm</font>
</p>
CLUE: The base is rotated
<br/></body>

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  Answer: <input type="text" name="number" /><br />
</select>
<input name="submit" type="submit">
</form>

<?php
if(isset($_POST['submit'])){

$number = $_POST['number'];
if ($number == "scuba"){
header("Location: http://localhost/index-3.php");
exit();}
}
?>

</html>

You can't have any output written to the browser if you want to use a HTTP header command.  Not even a space or new line.  PHP apps tend to be written so all PHP processing is done before output is written.  That way, you can determine if you need to redirect, or display something, and do either without interruption.  Its a good habit to get into.

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.