Jump to content

Syntax errors.


kir

Recommended Posts

I am getting tons of errors when I try and run this....  If you can find out why plz post it below! Thanks in advance.

--------------------------------------------------------------------------

<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
 
?>
<!DOCTYPE html PUBLIC>
    <html>
        <head>
            <title>Login</title>
        </head>
<body>
    <?php
    
    $form = "<form action='./login.php' method='post'>"
    
    <table>
    <tr>
        <td>Username:</td>
        <td><imput type='text' name='user' /></td>
    </tr>
    <tr>
        <td>Password:</td>
        <td><imput type='password' name='password' /></td>
    </tr>
    <tr>
        <td></td>
        <td><imput type='submit' name='loginbtn' value='Login' /></td>
    </tr>
    </tr>
    </table>
    </form>";
    
   if ($_POST['loginbtn']){
       $user = $_POST['user'];
       $password = $_POST['password'];
       
       if ($user){
         if ($password){
         echo "$user - $password <hr /> $form";
         } 
         else
            echo "You must enter your password. $form";
       }
       
       else
            echo "You must enter your username. $form";
   }
   
    else
        echo $form;
    
    
    
    ?>
 
</body>
</html>
---------------------------------------------------------------------------------
Link to comment
https://forums.phpfreaks.com/topic/287982-syntax-errors/
Share on other sites

1 - read the rules and post using the proper tags.

2 - how about giving us a couple of your error messages?

3 - php statements must end with a semi

4 - separate your html code from your php code and you won't leave php mode on while you are typing html and vice versa.  Coders who mingle html/js/php in their scripts are just asking for pain and confusion.

Link to comment
https://forums.phpfreaks.com/topic/287982-syntax-errors/#findComment-1477137
Share on other sites

- your file should also be named login.php

- line 16  - you can't make php variable equal to HTML tags

- you have multiple syntax error 'imput' instead of 'input'

 

 
<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();

?>
<!DOCTYPE html PUBLIC>
<html>
<head>
<title>Login</title>
</head>
<body>


<form action='./login.php' method='post'>
<table>
<tr>
<td>Username:</td>
<td><input type='text' name='user' /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password' /></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='loginbtn' value='Login' /></td>
</tr>
</tr>
</table>
</form>
 
<!-- PHP form handling code starts here -->
<?php
if ($_POST['loginbtn']){
$user = $_POST['user'];
$password = $_POST['password'];

if ($user){
if ($password){
echo "$user - $password <hr /> $form";
}
else
echo "You must enter your password. $form";
}

else
echo "You must enter your username. $form";
}

else
echo $form;



?>

</body>
</html>
 

Link to comment
https://forums.phpfreaks.com/topic/287982-syntax-errors/#findComment-1477147
Share on other sites

Oh, I agree. Generally you can make a string variable containing some HTML (or whichever) code. 

 

 
$name = "John";
$op_tags = "<b>";
$end_tags="</b>";
 
echo "You must enter your password, $op_tags $name $end_tags.";

 

which would output:

 

You must enter your password, John .

 

My impression was that OP was hoping to put the whole HTML form inside a variable for execution purpose (if it can be said like that). In my example in previous post, he should also delete all $form because they have no purpose anymore.

Link to comment
https://forums.phpfreaks.com/topic/287982-syntax-errors/#findComment-1477161
Share on other sites

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.