【问题标题】:PHP Form , session data not being storedPHP表单,未存储会话数据
【发布时间】: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


【解决方案1】:

尝试显示 mysql_error 并查看问题所在

mysql_query($sql) or die(mysql_error());

【讨论】:

  • 谢谢,但它给出了这个错误 INSERT command denied to user ''@'localhost' for table 'people
  • 你的mysql有权限问题。检查您的权限!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-01
  • 2020-01-07
  • 2013-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多