This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
first file is index.php
<?php include('loginform.php');?>
second file is loginform.php
<?php
<html>
<body>
<form action="" method="post">
<label>Username</label>
<input type="text" name="username"><br>
<label>Password></label>
<input type="password" name="password"><br>
<input type="submit" name="submit" value="login">
</form>
Register here
</body>
</html>
?>
third file is register.php
<html>
<body>
<form action="" method="post">
<label>FirstName</label>
<input type="text" name="firstname"><br>
<label>LastName</label>
<input type="text" name="lastname"><br>
<label>Email</label>
<input type="email" name="email"><br>
<label>UserName</label>
<input type="text" name="username"><br>
<label>Password</label>
<input type="password" name="password"><br>
<input type="submit" name="submit" value="Register">
</form>
</body>
</html>
I have three files in the project first file is the index file which is shown whenever the user opens the website It contains two things login form and a link
ie register here.So i have wrapped all this in one single php file loginform.php
and included it in my index.php file so when I execute this in my localhost web server it shows a error like this
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\cms\loginform.php on line 2
How can I tackle this problem please tell me?
The loginform.php file isn't a PHP source file, it's just an HTML file. Remove the enclosing <?php and ?> from it and you should be OK.
Related
This question already has answers here:
How can I get useful error messages in PHP?
(41 answers)
Closed 2 years ago.
My html is not sending field data to php in same file until action and method attribute are placed.... kindly identify my error and guide me.....
<pre><code>
<?php
if(isset($_post['submit'])){
echo "Yes is is working";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>testing form</title>
</head>
<body>
<br><br><br><br>
<form action="test.php" method="post">
<input type="text" name="name" placeholder="Enter Name"><br>
<input type="text" name="location" placeholder="ENter location"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
</pre></code>
Probably you could try by setting id instead of name.
Eg.
<form action="test.php" method="post">
<input type="text" id="name" placeholder="Enter Name"><br>
<input type="text" id="location" placeholder="ENter location"><br>
<input type="submit" id="submit">
</form>
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 5 years ago.
I am trying to load my start page (php) on localhost with xampp. As long as I keep the file an html document (saved as start.html) it is showing up but as soon as I save it as a php file (in order to execute the $_SESSION['id'] it fails to load the file (basically an infinite loading process but no errors showing up. Here is my code. Any help is highly appreciated. Thanks
<?php
session_start();?>
<html>
<head>
<title>
I am a login project
</title>
<meta charset="utf-8">
<link rel="stylesheet" href='style.css' type="text/css">
</head>
<body>
<form method="post" action="login.php">
<input type="text" placeholder="uid" name="Username">
<input type="password" placeholder="Password" name="pwd">
<button type="submit" name="submit">LOGIN</button>
</form>
<br>
<?php
if(isset($_SESSION['id'])){
echo $_SESSION['id'];
}
?>
<form method="post" action="signup.php">
<input type="text" placeholder="first" name="first">
<input type="text" placeholder="last" name="last">
<input type="text" placeholder="uid" name="Username">
<input type="password" placeholder="Password" name="pwd">
<button type="submit" name="submit">SIGN_UP</button>
</form>
<br>
<form method="post" action="logout.php">
<button type="submit" name='logout'>LOGOUT</button>
</form>
</body>
</html>
session start should happen before any output. there is a space before your opening php tag
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 6 years ago.
I am trying to conditionally create a fieldset in the top right of my website that will either prompt the user to login, or show their username and give them the option to logout.
I am using embedded php within my html document in order to achieve this. Unfortunately, both fieldsets are being displayed on my webpage. Can someone please explain to me what I am doing wrong? Thank you!
<div id="loginForm">
<?php
session_start();
if(isset($_SESSION['username'])){ ?>
<form action="endsession.php" method="post">
<fieldset width="100">
<legend>Welcome</legend>
<h3></h3>
<input type="submit" value="Logout"></input>
</fieldset>
</form>
<?php } else{ ?>
<form action="connection.php" method="post">
<fieldset width="100">
<legend>Login</legend>
<input type="hidden" name="submitted" id="submitted" value="1"/>
<label for="username">Username:</label>
<input id="username" name="username" type="text" ><br><br>
<label for="password">Password:</label>
<input id="password" name="password" type="password"/><br><br>
<input type="submit" value="Sign in"></input>
</fieldset>
</form>
<?php } ?>
</div>
Put session_start(); at the top of your page before any other code; just after PHP start tag
<?php
session_start();
<div id="loginForm">
....
and so on...
Hope it fixes the problem.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
<form action="form1.php" method="POST">
username <input type="text" name="username"><br />
password <input type="password" name="password"><br />
<input type="submit" name="submitbutt" value="Login!"><br />
</form>
when to add the lines on the code,the procedure runs error :
Parse error: syntax error, unexpected '<' in C:\wamp\www\form1.php on line 2
<?php
<form action="form1.php" method="POST">
username <input type="text" name="username"><br />
password <input type="password" name="password"><br />
<input type="submit" name="submitbutt" value="Login!"><br />
</form>
?>
You're putting HTML in a PHP block, so your web server is trying to parse the HTML as PHP - and fails, so you get an error back.
All you have to do is not enclose it in <?php ... ?>, and the HTML will show nicely. You only have to use <?php ... ?> when you have actual PHP code to place within it.
echo the html code...
<?php
echo '<form action="form1.php" method="POST">
username <input type="text" name="username"><br />
password <input type="password" name="password"><br />
<input type="submit" name="submitbutt" value="Login!"><br />
</form>';
?>
Or use only html
<?php #your php code ?>
<form action="form1.php" method="POST">
username <input type="text" name="username"><br />
password <input type="password" name="password"><br />
<input type="submit" name="submitbutt" value="Login!"><br />
</form>
<?php #your php code ?>
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 8 years ago.
I was following a guide on creating a secure log in with PHP, it was relatively easy to understand since I am very new to the language. When I finished I tried to check it out on my MAMP server, and none of the form for the register page shows up. What could be causing this?
tutorial I used here: http://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL
The Code in Question: (HTML / PHP)
<form action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>"
method="post"
name="registration_form">
Username: <input type='text'
name='username'
id='username' /><br>
Email: <input type="text" name="email" id="email" /><br>
Password: <input type="password"
name="password"
id="password"/><br>
Confirm password: <input type="password"
name="confirmpwd"
id="confirmpwd" /><br>
<input type="button"
value="Register"
onclick="return regformhash(this.form,
this.form.username,
this.form.email,
this.form.password,
this.form.confirmpwd);" />
</form>
I have tried using a different style of formatting, but I believe it's directly related to the echo esc_url in the form action, any ideas on fixing this?
My form does display with this syntax:
<form>
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
At first try clearing your cache in the browser , check if every file is correct in your MAMP.
<form action="" method="post" >
replace:
<input type="button"
value="Register"
onclick="return regformhash(this.form,
this.form.username,
this.form.email,
this.form.password,
this.form.confirmpwd);" />
to:
<input type="submit" value="register"name="register">
PHP:
if(isset($_POST['register']))
{
//whatever you want your form to do
}