-5

I'm getting a syntax error

Parse error: syntax error, unexpected 'text' (T_STRING) in C:... line 18.

I don't exactly know why I am getting this error. The sooner the response the better. Thank you very much.

<?php
session_start();
?>
<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Login</title>
</head>
    <body>
        <div align="center">
            <img src="logo.png" alt="school logo">
            <h2>login</h2>
            <?php
            $form="<form action='./login.php'  method='post'>
            <table>
            <tr>
                <td>Email:</td>
                <td>input type="text" name:"Email"/></td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><input type="text" name:"Password"/></td>
            </tr>
            <tr>
                <td><</td>
                <td><input type="submit" name="loginbtn" value="login"/></td>
            </tr>
            </table>
            </form>";

            if ($_POST['loginbtn']){
                $email=$_POST["email"];
                $Password=$_POST["Password"];

                if($email){
                    if($Password){
                    }
                    else
                        echo"you must enter your password .$form";
                }
                else
                    echo "you must enter your email .$form";

            }
            else
                echo"";
            ?>
        </div>
    </body>
</html>
srhgrsdhfdh
  • 5
  • 2
  • 5
  • 1
    http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – Vasil Rashkov Mar 07 '16 at 04:47
  • Try re-writing the question to include what you've tried, what you think is happening, and a small (minimal) code example that re-produces your problem. – mprat Mar 07 '16 at 04:53
  • You are forgetting your open and close-tags for php. – CerebralFart Mar 07 '16 at 05:09
  • Where exactly is this error occurring? How do you expect someone to find line 18 in your post? You may also have a look at [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) to improve the question. Welcome to SO! – Debosmit Ray Mar 07 '16 at 05:21

4 Answers4

1

try this

<?php
session_start();
?>
<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Login</title>
</head>
    <body>
        <div align="center">
            <img src="logo.png" alt="school logo">
            <h2>login</h2>
            <?php
            $form="<form action='./login.php'  method='post'>
            <table>
            <tr>
                <td>Email:</td>
                <td>input type='text' name:'Email'/></td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><input type='text' name:'Password'/></td>
            </tr>
            <tr>
                <td><</td>
                <td><input type='submit' name='loginbtn' value='login'/></td>
            </tr>
            </table>
            </form>";

            if ($_POST['loginbtn']){
                $email=$_POST["email"];
                $Password=$_POST["Password"];

                if($email){
                    if($Password){
                    }
                    else
                        echo"you must enter your password .$form";
                }
                else
                    echo "you must enter your email .$form";

            }
            else
                echo"";
            ?>
        </div>
    </body>
</html>

change double column to single column

naseeba c
  • 1,040
  • 2
  • 14
  • 30
1

You need to escape the " in your HTML.

$form="<form action='./login.php'  method='post'>
            <table>
            <tr>
                <td>Email:</td>
                <td>input type=\"text\" name:\"Email\"/></td>
            ...
            </form>";
Matthew Herbst
  • 29,477
  • 23
  • 85
  • 128
0

The easiest way of doing this would be the following:

<?php
session_start();
?>
<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Login</title>
</head>
    <body>
        <div align="center">
            <img src="logo.png" alt="school logo">
            <h2>login</h2>
            <?php
            if (isset($_POST['loginbtn'])){ //Use isset otherwise you may get undefined variable errors
                $email=$_POST["email"];
                $Password=$_POST["Password"];
                if(!empty($email) || !empty($Password)) //If you use !$email and the variable isn't set, you get a warning.
                {
                    if(!empty($email)) //Empty checks if it exists + has a value
                        echo "you must enter your password<br />"; //Must add a new line with <br />
                    if(!empty($Password))
                        echo "you must enter your email <br />";
                    ?>
                    <form action='./login.php'  method='post'>
                        <table>
                            <tr>
                                <td>Email:</td>
                                <td>input type="text" name:"Email"/></td>
                            </tr>
                            <tr>
                                <td>Password:</td>
                                <td><input type="text" name:"Password"/></td>
                            </tr>
                            <tr>
                                <td><</td>
                                <td><input type="submit" name="loginbtn" value="login"/></td>
                            </tr>
                        </table>
                    </form>
                    <?php
                }
            }
            ?>
        </div>
    </body>
</html>

It fixes issues like:

  • Your syntax issue
  • Doesn't require putting a lot of HTML in a string
  • Fixes any possible undefined indexes using isset or empty
  • Condenses code and makes it easier to read.
Matt
  • 2,851
  • 1
  • 13
  • 27
0

You have used double-qoute("") to assign value for $form. So you should ideally use single-qoute in side it.Like:

    $form="<form action='./login.php'  method='post'>
                    <table>
                    <tr>
                        <td>Email:</td>
                        <td>input type='text' name:'Email'/></td>
                    </tr>
                    <tr>
                        <td>Password:</td>
                        <td><input type='text' name:'Password'/></td>
                    </tr>
                    <tr>
                        <td><</td>
                        <td><input type='submit' name='loginbtn' value='login'/></td>
                    </tr>
                    </table>
                    </form>";

Or you can use Double-quote by using escape string like:

    $form="<form action='./login.php'  method='post'>
        <table>
        <tr>
            <td>Email:</td>
            <td>input type=\"text\" name:\"Email\"/></td>
        </tr>
        <tr>
            <td>Password:</td>
            <td><input type=\"text\" name:\"Password\"/></td>
        </tr>
        <tr>
            <td><</td>
            <td><input type=\"submit\" name=\"loginbtn\" value=\"login\"/></td>
        </tr>
        </table>
        </form>";
Aman Agarwal
  • 132
  • 7