0
<?php
session_start(); 
if (!isset($_SESSION)){
}
$total_amt=$_POST['total_amt'];
   $total_seats=$_POST['total_seats'];
   $boarding_point=$_POST['boarding_point'];
   $_SESSION['total_amt']=$total_amt;
   $_SESSION['total_seats']=$total_seats;
   $_SESSION['boarding_point']=$boarding_point;
?>
<?php
require_once("config.php");
$source_point=$_SESSION['source_point'];
$destination=$_SESSION['destination'];
$datepick=$_SESSION['datepick'];
$_SESSION['total_amt']=$total_amt;
$_SESSION['total_seats']=$total_seats;
$boarding_point=$_POST['boarding_point'];

// Insert data into mysql
$sql="INSERT INTO book_seat(from, to, datepick, total_amt, total_seats,    boarding_point) VALUES 
    '{$_SESSION['source_point']}',
    '{$_SESSION['destination']}',
            '{$_SESSION['datepick']}',
    '{$_SESSION['total_amt']}',
            '{$_SESSION['total_seats']}',
        '{$_SESSION['boarding_point']}')";
$result=mysql_query($sql);
if(isset($_POST['chksbmt']) && !$errors) 
{
    header("location:booking_detail.php");
}
if(!$sql) die(mysql_error());

mysql_close();

?>

I want to insert my session variables to my database..

This is my code, there is no error happening, page is redirecting to booking_detail.php but also these session variables are not getting inserted to my database also..

2
  • there is no error as i ve mentioned, bt my data are not getting inserted . Commented Nov 19, 2013 at 7:45
  • comment the line and retry and then check the error.. //header("location:booking_detail.php"); Commented Nov 19, 2013 at 7:47

6 Answers 6

1

From and to are reserved word,use backticks

Reserved words in Mysql

$sql="INSERT INTO book_seat(`from`, `to`, datepick, total_amt, total_seats,    boarding_point) VALUES 
    '{$_SESSION['source_point']}',
    '{$_SESSION['destination']}',
            '{$_SESSION['datepick']}',
    '{$_SESSION['total_amt']}',
            '{$_SESSION['total_seats']}',
        '{$_SESSION['boarding_point']}')";
Sign up to request clarification or add additional context in comments.

2 Comments

its fixed .. i just changed my column name 'from' to leaving_from /. Now all the data are inserted xcept that leaving_from data , so i think i can fix that .. thank u 4 ur help ..
yeah only that 'from' and 'to' words are the problems
0

Comment out your header(), turn on error reporting using error_reporting(-1), check mysql_error() and then fix that problem.

From now I can see that you've got syntax error in sql query because you're using from as column name which is restricted word. You have to put it in `.

Comments

0

remove the space from top

<?php session_start(); 

if this didn't work

var_dump($_SESSION) before inserting to check value exist in the session and use die(mysql_error()); with the query

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

2 Comments

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, to, datepick, total_amt, total_seats, boarding_point) VALUES ' at line 1 : i got this erro
its fixed .. i just change my column name from to leaving_from /. Now all the data are inserted xcept that , so i think i can fix that .. thank u 4 ur help
0
if(isset($_POST['chksbmt']) && !$errors) 
{
header("location:booking_detail.php");

}

Above code will be executed once the form is submitted if chksbmt is the name of the submit button. It takes to that page mentioned in header before inserting. Write all your stuff in between above curly braces, use

if(isset($_POST['chksbmt']) && !$errors) 
{
 //all your stuff, ex:storing in DB.
  if($result){
   header("location:booking_detail.php");

  }
}

I hope that I've understood your problem, this will workout.

1 Comment

its fixed .. i just changed my column name 'from' to 'leaving_from' /. Now all the data are inserted xcept that , so i think i can fix that .. thank u 4 ur help
0

First remove quotes from all session variables like:

{$_SESSION['source_point']}

Second you're redirecting before mysql_error check, Check on results and error first and then redirect:

if (!$result) {
  die(mysql_error());
}

if(isset($_POST['chksbmt']) && !$errors) 
{
 header("location:booking_detail.php");
}

2 Comments

but v need to give quotes when we declare something in VALUES na
ohh i did that n got my error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, to, datepick, total_amt, total_seats, boarding_point) VALUES ' at line 1
0

1) Start session if its separate script.
2) Remove reserved keyword as suggested by @Mihai in your query.
3) In your query It should be VALUES( instead of VALUES.
4) As you are mention in your comment leaving_from not inserting into Db. Because in your script you have not assign session value for $_SESSION['source_point'] .

In your script will be :-

<?php
session_start(); 
   if (!isset($_SESSION)){
}

$total_amt  =   $_POST['total_amt'];
$total_seats =  $_POST['total_seats'];
$boarding_point =   $_POST['boarding_point'];

$_SESSION['total_amt']  =   $total_amt;
$_SESSION['total_seats']    =   $total_seats;
$_SESSION['boarding_point'] =   $boarding_point;
// Set here session value for $_SESSION['source_point'] as well,

5 Comments

Can you echo your DB query and run into query browser.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, to, datepick, total_amt, total_seats, boarding_point) VALUES ' at line 1 the error
its fixed .. i just change my column name from to leaving_from /. Now all the data are inserted xcept that , so i think i can fix that .. thank u 4 ur help
Welcome @Pooja ji..:)
bt my leaving_from data is not getting inserted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.