【发布时间】:2011-08-31 03:30:11
【问题描述】:
我们正在处理 php 会话数据,但数据并未存储在数据库中
登录.php
<h2>Welcome</h2>
<form action = "Customer.php" method = "POST">
Customer Name:<input type = "text" name="customerName">
<input type = "submit" name = "submit">
</form>
客户.php
<?php
session_start();
#include("Connection.php);
if (isset($_POST['submit'])) {
$name = $_POST['customerName'];
$_SESSION['user'] = $name;
}
if (isset($_SESSION['user']))
{
echo "Hello {$_SESSION['user']}, welcome to starbucks!";
}
else
{
echo "walang tao";
$sql="INSERT INTO `customer`.`people` ('ID', `NAME`) VALUES ('','$name')";
mysql_query($sql);
?>
<a href = "logout.php">Logout</a>
和logout.php
<?php
session_start();
session_destroy();
?>
<a href = "index.php">Click me to return to login </a>
请告诉我怎么了
【问题讨论】:
-
你应该删除#include("Connection.php); 中的#;
-
向查询添加一些基本调试。
-
从会话中检索数据时将数据保存到 mysql 与在代码中指定为字符串文字有区别吗?
-
另外,你在 mysql_query($sql); 后面少了一个 };
-
您在没有会话数据的情况下进行插入,您希望如何保存?甚至它在
else块之外,仍然没有会话数据,因为您依赖isset($_POST['submit'])来获取分配给会话变量的内容。
标签: php mysql database session