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
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:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
I have a question here. Somehow my created registration form doesn't appear on the website. When I am deleting all the include files, it shows, but with the files - it does not. Could someone help me to solve this problem? What I'm doing wrong?
Here is my register.php file:
<!DOCTYPE html>
<?php
include 'classes/connection.php';
include 'classes/register.php';
$connection = new Connection();
$users = new Users($connection);
$users->insertUserValues();
?>
<html>
<head>
<meta charset="UTF-8">
<title>
</title>
</head>
<body>
<div class="form">
<form method ="post" action="register.php">
Vardas:<br>
<input type="text" name="name" id="name" placeholder="Vardas" required>
<br>
Pavardė:<br>
<input type="text" name="surname" id="surname" placeholder="Pavardė" required>
<br>
Prisijungimo vardas:<br>
<input type="text" name="username" id="username" placeholder="Prisijungimo vardas" required>
<br>
Slaptažodis:<br>
<input type="password" name="password" id="password" placeholder="Slaptažodis" required>
<br>
Patvirtinti slaptažodį:<br>
<input type="password" name="confirm_password" id="confirm" placeholder="Slaptažodis" required>
<br>
El. pašto adresas: <br>
<input type="email" name="email" id="email" placeholder="El. pašto adresas" required>
<br><br>
<input type="submit" name="submit" id="submit" value="Registruotis">
</form>
</div>
</body>
The link I'm entering to the registration form is correct, I've also tried to go from index.php, but it's the same..
Without checking if $_POST['submit'] was set (or any other post var), you immediately call $users->insertUserValues();
What happens inside that? Can we see? I would suggest an if statement to check the form was posted before trying to process non-existent data.
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.
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.
I am using Post method in my website. In my index.html file is the following code:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Heater Login</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<form method="post" action="login.php" class="login">
<p>
<label for="login">Username:</label>
<input type="text" name="login" id="login" value="John Appleseed">
</p>
<p>
<label for="password">Password:</label>
<input type="password" name="password" id="password" value="4815162342">
</p>
<p class="login-submit">
<button type="submit" class="login-button">Login</button>
</p>
</form>
</body>
</html>
And in my login.php file is the following code:
<?php
echo($_POST['login']);
echo($_POST['password']);
?>
When I open html file, enter my credentials, click submit button it goes to php file end there's nothing.
Can you change this line of code with the new one Hope it will work
<button type="submit" class="login-button">Login</button>
<input type="submit" name="submit" value="Login">
And last I want that you copy whole code from the stackoverflow and use this code.Some times space may create a problem.
This problem occurs when you directly open from its file location try opening file from server
like if you're using xampp open localhost and then try.