dadamssg Posted January 18, 2009 Share Posted January 18, 2009 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: </b></td><td>{$_SESSION['title']}</td> </tr> <tr> <td><b>Description: </b></td><td>{$_SESSION['description']}</td> </tr> <tr> <td><b>Event Type: </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."); ?> Link to comment https://forums.phpfreaks.com/topic/141314-entering-session-variables-into-database/ Share on other sites More sharing options...
Mchl Posted January 18, 2009 Share Posted January 18, 2009 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']; // Link to comment https://forums.phpfreaks.com/topic/141314-entering-session-variables-into-database/#findComment-739648 Share on other sites More sharing options...
Daniel0 Posted January 18, 2009 Share Posted January 18, 2009 You already have several other topics about this: http://www.phpfreaks.com/forums/index.php/topic,234564.0.html http://www.phpfreaks.com/forums/index.php/topic,234530.0.html http://www.phpfreaks.com/forums/index.php/topic,234559.0.html Link to comment https://forums.phpfreaks.com/topic/141314-entering-session-variables-into-database/#findComment-739651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.