0

we are working with php session data, but the data is not being stored in the database

login.php

<h2>Welcome</h2> <form action = "Customer.php" method = "POST"> Customer Name:<input type = "text" name="customerName"> <input type = "submit" name = "submit"> </form> 

Customer.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> 

and logout.php

<?php session_start(); session_destroy(); ?> <a href = "index.php">Click me to return to login </a> 

please tell me what's wrong

7
  • 1
    You should maybe remove the # in #include("Connection.php); Commented Aug 31, 2011 at 3:34
  • 1
    ad some basic debugging to the query. Commented Aug 31, 2011 at 3:35
  • Is there a difference in saving the data to mysql when it is retrieved from session vs specified right in the code as string literals? Commented Aug 31, 2011 at 3:35
  • also, you missing a } after mysql_query($sql); Commented Aug 31, 2011 at 3:36
  • you're doing an insert inside of the condition of no session data, how do you expect that to get saved? or even it's outside of that else block, there is still no session data because you're depending on isset($_POST['submit']) to get something assigned to your session variable. Commented Aug 31, 2011 at 3:44

1 Answer 1

1

try displaying the mysql_error and see what the problem is

mysql_query($sql) or die(mysql_error()); 
Sign up to request clarification or add additional context in comments.

2 Comments

thanks but it gave this error INSERT command denied to user ''@'localhost' for table 'people
You have a permissions problem with mysql. Check your privileges!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.