0

I do apologise in advance for my lack of knowledge in PHP and HTML. I have scoured the internet for 3/4 days trying to create what is probably a simple system. I need the user to enter a digit before the next page is loaded. I have an IF statement on my page. 1.php

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <link href="css/reset.css" rel="stylesheet" type="text/css" />
<div id="container">
<div id="authorise">
<form action="2.php" method="post">
<!--Product Comment Box--><br>
<p>Please enter your 4<br> digit authorisation code:<br> <br>
<input type="text" name="digits" />
<input type="submit" name="submit" />
</form>
</div>
</div> 

2.php

<?php
  if ($_POST['digits'] === '210392') 
  {echo 'https://www.facebook.com/'
 ?>

But I need a form first which the user would input the code '210392' and press submit. Then the if statement can take place. I know how to do a form but dont know how to assign that form a variable name 'digits'. All help is appreciated.

2
  • 1
    It would be helpful if you would post the code for form and what you have tried so far. The code that you posted does not help much by itself and it is possible that some other part of the code might be giving you problem. Commented Mar 19, 2014 at 21:24
  • if ($digits == '210392'; this is not correct, last ; should be a ) Commented Mar 19, 2014 at 21:27

5 Answers 5

4

A basic form:

<form action="your_file.php" method="post">
  <input type="text" name="digits" />
  <input type="submit" name="submit" />
</form>

Then in your_file.php:

<?php
  if ($_POST['digits'] === '210392') {
  // etc.

$_POST is a superglobal array that has all data POSTed to your script. digits in this case is an index in that array. It comes from the name of the input field.

Sign up to request clarification or add additional context in comments.

4 Comments

I'd add a button as well.
@TimWolla Good call. :-D
I'll give that a whirl and report back. Thanks
<?php if ($_POST['digits'] === '210392') {echo 'facebook.com' ?> Tried that it doesnt work?
0
<form action="check.php" method="POST">
<input type="text" name="digits" />
<input type="submit" value="click here" />
</form>

//in check.php 

if (isset($_POST['digits']) and $_POST['digits'] == 12345){
header("Location: http://google.com");
} 
else {
echo " error !!";
}

study html from w3school http://www.w3schools.com/html/html_forms.asp

and php http://www.w3schools.com/PhP/php_forms.asp

Comments

0
    <form action="https://scm-intranet.tees.ac.uk/users/l1071039/bobbin/admin.php" method="post">
      Password : <input type="password" name="pwd" />
      <input type="submit" name="send">
    </form>

    // admin.php
    <?php 
    if( isset($_POST['pwd']) ){
        $pwd = $_POST['pwd'];
    }
    ?>

1 Comment

Jonty is trying to handle this with PHP, not JavaScript.
0

You first need to create an input with the very important name attribute which you'll use later.

<form method="post">
    <input type="password" name="mypassword" />
    <button type="submit">Go</button>
</form>

PHP:

//Post method access with $_POST variable:
if ($_POST['mypassword'] == 'my-password') { //Oh, you should probably use SSH and hash the password
    //Hooray!
}

2 Comments

A hash is not encryption, and that hash shouldn't be done client-side anyway.
@Brad Sorry, got 2 concepts confused. And typo.
0

Instead of echo, use header.

   <?php
   if ($_POST['digits'] === '210392') 
   {
   header (loaction:https://www.facebook.com/);
   }
   ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.