JBuss1503 Posted March 18, 2014 Share Posted March 18, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/287046-echo-issue-in-phphtml/ Share on other sites More sharing options...
JBuss1503 Posted March 18, 2014 Author Share Posted March 18, 2014 (edited) It appears I was missing a bracket in the line 23. However I now get this error Notice: Undefined variable: authorisation in /web/users/l1071039/bobbin/login.php on line 21 https://www.google.co.uk Edited March 18, 2014 by JBuss1503 Quote Link to comment https://forums.phpfreaks.com/topic/287046-echo-issue-in-phphtml/#findComment-1472965 Share on other sites More sharing options...
cyberRobot Posted March 18, 2014 Share Posted March 18, 2014 It means that your $authorise variable is undefined. Is that variable supposed to come from the form? If so, you'll want to look into using $_POST and isset(). Quote Link to comment https://forums.phpfreaks.com/topic/287046-echo-issue-in-phphtml/#findComment-1472966 Share on other sites More sharing options...
JBuss1503 Posted March 18, 2014 Author Share Posted March 18, 2014 No. Can I change the 'if' code so that it knows to check the content of the form? THanks Quote Link to comment https://forums.phpfreaks.com/topic/287046-echo-issue-in-phphtml/#findComment-1472968 Share on other sites More sharing options...
cyberRobot Posted March 18, 2014 Share Posted March 18, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/287046-echo-issue-in-phphtml/#findComment-1472969 Share on other sites More sharing options...
JBuss1503 Posted March 18, 2014 Author Share Posted March 18, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/287046-echo-issue-in-phphtml/#findComment-1472971 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.