[英]Storing Session Variable on button click, HTML, PHP
I am having trouble storing Session variable on a button click. 我在单击按钮时无法存储Session变量。 I am trying do this without use of a form. 我正在尝试不使用表单来执行此操作。 Here is the code I have for my html and PHP. 这是我的html和PHP代码。
<?php
session_start();
if(isset($_GET['oldsignin'])) {
$username = $_GET['oldusername'];
$_SESSION['oldusername']= $username;
}
?>
Below is my html file: 以下是我的html文件:
<div class="form-group">
<label for="text">Username:</label>
<input id = "oldusername" type="text" class="form-control" name="user" placeholder="Enter Username" required>
<a class="usersignin" name="oldsignin" data-role="button" style="background: blue; color: white;">Sign In</a>
</div>
Thanks Guys for your help and suggestions. 谢谢你们的帮助和建议。
PHP processes before the HTML file is sent to the client browser, so for inputted data to be processed, a page reload (form submission) needs to take place I'm afraid. PHP在将HTML文件发送到客户端浏览器之前进行处理,因此恐怕要进行输入数据的处理,需要重新加载页面(提交表单)。
(unless you use AJAX, you'll need to look that up) (除非您使用AJAX,否则需要进行查找)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.