Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have php session not working in chrome and IE but working fine in Firefox.
I'm getting this error in page4.:
it show variable empty in page4, session not passing in page4 after the user click click me in page3
Notice: Undefined index: username in /var/www/html/phptest/test4.php on line 5
Please see my code and let me know where the error is.
Page2
<html>
<body>
<form action="test3.php" method="post">
Username: <br><input type="text" name="username"></br>
<input type="submit" name = 'submit1' value= 'Login'>
</form>
</body>
</html>
Page3
<html>
<body>
<?php
session_start();
$username = $_POST['username'];
$_SESSION['username']= $_POST['username'];
echo "<br> Hi $username.</br>";
?>
<form action="test4.php" method="post">
<input type="submit" name = 'submit' value= 'click me'>
</form>
</body>
</html>
Page 4
<?php
session_start();
$username = $_SESSION['username'];
echo "<br> Hi $username.</br>";
?>
session_start() must go at the top of the page before any output:
<?php
session_start();
?>
<html>
<body>
<?php
$username = $_POST['username'];
$_SESSION['username']= $_POST['username'];
echo "<br> Hi $username.</br>";
?>
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
<?php
session_start();
?>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="pageContainer">
<form action="second.php" class="formLayout" method="post">
<div class="formGroup">
<label>Name:</label>
<input type="text" name="first_name"><br>
<input type="hidden" name="postback" value="true"><br>
</div>
<div class="formGroup">
<label> Car model:</label>
<div class="formElements">
<input type="radio" name="model" value="Mustang">Ford Mustang<br>
<input type="radio" name="model" value="Subaru">Subaru WRX STI<br>
<input type="radio" name="model" value="Corvette">Corvette<br>
</div>
<input type="submit" name="submit">
</form>
<?php
if (isset($_POST['submit'])) {
$_SESSION["first_name"] = $_POST["first_name"];
$_SESSION["model"] = $_POST["model"];
}
?>
</div>
</body>
</html>
I set up my code to set the value of the "first_name" and "model" names into my session variables.
When I try to access the values of the stored variables in the submission page of the form:
<?php
session_start();
?>
<html>
<body>
<?php
echo $_SESSION["first_name"];
echo $_SESSION["model"];
?>
</body>
</html>
I only receive the out of the model value, not the first_name value. I don't understand what I'm doing wrong here.
Let's assume your first file is called first.php. As shown in your <form>, the second one is second.php.
It seems that you are writing the data into the session in the first.php file, but this code will never run because you are submitting your form to second.php and not first.php!
So, move the code that writes the session variables into second.php instead. To test that it really worked, you can create a third.php to display them.
(I'm not sure why see the model set, but I guess it's still there from a previous test you did.)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
this is my html code
<?php include('process.php') ?>
<!doctype html>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
<from action="index.php.php" method="post">
<?php include('errors.php'); ?>
<lable> name </lable>
<input type="text" name="name" placeholder="enter your name">
<lable>location</lable>
<input type="text" name="location" placeholder="enter your location">
<button type="submit" name="save_btn" >update</button>
</from>
</body>
</html>
this is my php code
<?php
session_start();
// initializing variables
$name="";
$location="";
// connect to the database
$db = mysqli_connect('localhost', 'newuser', 'password', 'curd');
// REGISTER USER
if (isset($_POST['save_btn'])) {
// receive all input values from the form
$name = mysqli_real_escape_string($db, $_POST['name']);
$location = mysqli_real_escape_string($db, $_POST['location']);
$query = "INSERT INTO data (name, location) VALUES('$name', '$location')";
mysqli_query($db, $query);
}
why its not store in data base? data base name correct and i have 3 tables
id (ai)
name (var 200)
location (var 200)
in my browser i can locate index.php but when i click button nothing happen any one can explain why its not working?
Fine, it seems that the problem is caused by 2 important typos:
<from action="index.php.php" method="post"> should be <form action="index.php" method="post">.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
session_start() is called in connect.php but is not included here for security reasons
I am having trouble with a session not being unset or destroyed
I have a logout.php where i handle the logging out and it looks like this
<?
if(isset($_POST['logout'])){
session_start();
session_unset();
session_destroy();
header("Location: index.php");
}
?>
I then call this code in my navigation which is working fine however once i log in and try to log out the navigation should go away and the forms should be displayed but the navigation is the only thing being display here is that script
<nav>
<?
if(isset($_SESSION['user'])){
include("server/constants/nav.php");
} else{?>
<div class="form">
<input type="button" id="displayLoginForm" onclick="showLogin()" value="Login">
<input type="button" id="displayRegisterForm" onclick="showRegister()" value="Register">
<div id="loginSection" style="display:none">
<? include("server/display/LoginForm.php") ?>
</div>
<div id="registerSection" style="display:none">
<? include("server/display/RegisterForm.php") ?>
</div>
</div>
<? } ?>
</nav>
Other relevant scripts
HandleLogin.php
<?
if(isset($_POST['Login'])){
$user = $_POST['username'];
$pass = $_POST['password'];
$sql = "SELECT * FROM energywise WHERE username='$user'";
$query = mysql_query($sql);
$row = mysql_fetch_object($query);
$id = htmlspecialchars($row->id);
$firstName = htmlspecialchars($row->firstname);
$lastName = htmlspecialchars($row->lastname);
$username = htmlspecialchars($row->username);
$password = htmlspecialchars($row->password);
$mail = htmlspecialchars($row->email);
if(empty($id)){
echo 'Account does not exist';
} elseif($pass != $password){
echo 'Passwords do not match';
} else{
$_SESSION['user'] = $id;
header("Location: index.php");
}
}
?>
nav.php
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/navigation.css">
<script src="js/nav.js"></script>
<div id='cssmenu'>
<ul>
<li class='active'><a href='index.php'>Home</a></li>
<li><a href='calender.php'>Calender</a></li>
<li><a href='locations.php'>Locations</a></li>
<li><a href='#'>Placeholder</a></li>
<form method="post">
<li><input type="submit" name="logout" value="Logout"></li>
</form>
</ul>
Well, I don't know, but did you test if logout.php is being accessed? I miss action="logout.php" on the form:
<form action="logout.php" method="post">
<li><input type="submit" name="logout" value="Logout"></li>
</form>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have an HTML Form and I am trying to get the values from the form in my php file.
<div id="qForm">
<form action="postComment.php" method="post" name="comment">
Name: <input type="text" name="askerName"><br>
Title: <input type="text" name="qTitle"><br>
<textarea maxlength="255" name="theQ"></textarea>
<input type="submit">
</form>
</div>
My PHP file looks like this but It echos as Welcome
<?php
$name = $_POST["askerName"];
echo $name; //this works
$textArea = $_POST["theQ"];
echo $textArea; //this does not work
?>
<html>
<head>
</head>
<body>
welcome <?php $_POST["askerName"]; ?>
</body>
</html>
Use
<body>
welcome <?php echo $_POST["askerName"]; ?>
</body>
instead.
you have to use print/echo to display your php output these two basic ways to get output: echo and print
<body>
welcome <?php print $_POST["askerName"]; ?>
</body>
else
<body>
welcome <?php echo $_POST["askerName"]; ?>
</body>
echo is marginally faster compared to print as echo does not return any value
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have a log in page that I want to pass a value to from another page... but it wont pass can anyone help me? please.
login page code:
<!DOCTYPE html>
<?php
ob_start();
session_start();
include('include/connect.php');
?>
<html>
<head>
<title>test</title>
</head>
<body>
<form action="" method="post">
<input type="text" name="username">
<input type="text" name="password">
<input type="submit" name="login" id="send" />
</form>
</body>
</html>
<?php
// Inialize session
if(isset($_POST['login'])){
$username=$_POST['username'];
$password=$_POST['password'];
$repcode=$_POST['repcode'];
// Include database connection settings
include('connection.php');
// Retrieve username and password from database according to user's input
$login = mysql_query("SELECT * FROM users WHERE username = '$username' and password = '$password'");
// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
$_SESSION['repcode'] = $_POST['repcode'];
// Jump to secured page
$stat = "UPDATE users SET status='login'";
mysql_query($stat);
header('Location: home2.php');
}else {
}
}
?>
page to be passed:
<!DOCTYPE html>
<?php
ob_start();
session_start();
include('include/connect.php');
?>
<html>
<head>
<title>test</title>
</head>
<body>
<form method="get">
<input type="text" name="username" value="<?php echo $_POST['username']; ?> "/>
<input type="text" name="repcode" value="<?php echo $_POST['repcode']; ?> "/>
</form>
</body>
</html>
I want to pass the username and repcode to another page and put it in textboxes. Can anyone help me with this...I'm new in php and still learning.
I don't understand the goal of your code, but you need to use $_SESSION instead of $_POST in the 2nd page if you want to use the values stored in SESSION:
<form method="get" >
<input type="text" name="username" value="<?php echo $_SESSION['username']; ?> "/>
<input type="text" name="repcode" value="<?php echo $_SESSION['repcode']; ?> "/>
</form>