Jump to content

entering session variables into database


dadamssg

Recommended Posts

i have two programs...one to display the inputs of a form which is working which i use session variables to transfer to the next page. then on the page where they can check theres a submit button to put it in my database. i think im not putting the session variables in the $sql correctly, or maybe i don't need to define the session variables again on the submit program?

 

check and display progam:

<?php

/* File: checkpost.php*/

include("caneck.inc");

session_start();

$_SESSION['title'] = $_POST['title'];
$_SESSION['description'] = $_POST['description'];
$_SESSION['event'] = $_POST['event'];



echo "<table border='7'>
       <tr>
       <td><b>Title:&nbsp</b></td><td>{$_SESSION['title']}</td>
       </tr>                        
       <tr>
       <td><b>Description:&nbsp</b></td><td>{$_SESSION['description']}</td>
       </tr>
       <tr>
       <td><b>Event Type:&nbsp</b></td><td>{$_SESSION['event']}</td>
       </tr>
       <tr>
       <td colspan=2><center><form action='submitpost.php' method='POST'><input type='submit' name='post' value='post'>
       </center></form>
       </td>                       
       </tr>
       </table>";
  
?> 

 

submit to database program:

 

<?php
/* File: submitpost.php*/

include("caneck.inc");

session_start();

$_SESSION['title'] = $_POST['title'];
$_SESSION['description'] = $_POST['description'];
$_SESSION['event'] = $_POST['event'];

$cxn = mysqli_connect($host,$user,$passwd,$dbname)
         or die("Couldn't connect"); 

$sql = "INSERT INTO test (title, description, event)
VALUES ('{$_SESSION['title']}','{$_SESSION['description']}','{$_SESSION['event']}')";

$result = mysqli_query($cxn,$sql)
         or die ("Couldn't execute query.");

?>

 

 

Since the values are written to session in checkpost.php you should not write them again in submitpost.php . What's more, $_POST being sent from checkpost.php is empty, so you're overwriting values already in session with empty data.

 

//get rid of that
$_SESSION['title'] = $_POST['title'];
$_SESSION['description'] = $_POST['description'];
$_SESSION['event'] = $_POST['event'];
//

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.