Jump to content

Echo Issue in php/html


JBuss1503

Recommended Posts

Hi Community, 

 

I have a page on my website which includes a form and a submit button. If a user enters the correct 6 digit code (210392) it will take them to a another page (Google in this example). However I get an error when I run it. My code is below:

<?php
session_start();
include('connection.php');
?>

<div id="authorise">
<form action="admin.html" method="POST" name="authorisation"><br>
<!--Product Comment Box--><br>
<p>Please enter your 4<br> digit authorisation code:<br> <br><input type="text" name="code"/></p><br>
<input type="submit" value="Log In"/>
</form>

<?php
if ( ($authorise != 210392)
echo "https://www.google.co.uk";
?>

The error I get is: 

 

 

 

Parse error: syntax error, unexpected T_ECHO in /web/users/l1071039/bobbin/login.php on line 24

 

All help is greatly appreciated. Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/287046-echo-issue-in-phphtml/
Share on other sites

It sounds like you're trying to use the value which was entered in the "code" input. If that's the case, you could use $_POST['code'].

if(isset($_POST['code']) && $_POST['code'] != 210392) {
     echo "https://www.google.co.uk";
}

Note: since $_POST['code'] will be undefined until the form is submitted, I used isset() to prevent the page from showing an undefined variable message.

Thanks for your help so far. I have made some changes including what you gave me and my code now looks like this

 

<form action="admin.php" method="POST" name="authorisation"><br>
<!--Product Comment Box--><br>
<p>Please enter your 4<br> digit authorisation code:<br> <br><input type="text" name="code"/></p><br>
<input type="submit" value="Log In"/>
</form>

<?php
if(isset($_POST['code']) && $_POST['code'] != 210392) {
     echo "https://www.google.co.uk";
}
?>

When I run it, I type I can leave it blank and it will take me to admin.php instead of google. Do I need to remove any code and how do I get it so that if the incorrect code is inputted it wont load the page. I having only started html/php last week so I am very new to this and all help is appreciated :)

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.