writing a record with $_SESSION values into a database table

tumatieu

New Member
I can't seem to write the values of my $_SESSION variable into a record of my database table which has an auto-incrementing Primary Key. I have looked in many places on the forum but cannot find the solution to my problem. My hunch is that I need to add something for the auto-increment to work, but I am not sure. The code I am using is shown below. What am I doing wrong?\[code\]<?php// SESSION FILEinclude ("sessionstart.inc");echo "<html> <head><title>Reports-SESSION</title></head> <body>";include ("misc.inc"); //THIS SETS $cxn AS MY VARIABLE TO CONNECT TO THE DATABASE// SELECT THE DATABASE TO USEmysqli_select_db($cxn,"carregistration") or die(mysqli_error($cxn));// SET TEST VALUES IN $_SESSION VARIABLE$_SESSION['OwnerCarIdentifier']='6Gh7J8';$_SESSION['CarType']='station car';// TEST TO SEE WHAT VALUES ARE NOW IN $_SESSIONforeach ($_SESSION as $field => $value){ echo "$field = $value<br />\n";}// THIS CONFIRMS THAT THE TWO $_SESSION VALUES ARE THERE AND AS SET ABOVEecho "<br />";// NOW WRITE VALUES FROM $_SESSION INTO A NEW RECORD IN THE DATABASEmysqli_query($cxn,"INSERT INTO 'car' (OwnerCarIdentifier,CarType) VALUES ('$_SESSION[OwnerCarIdentifier]','$_SESSION[CarType]')");//ERROR CHECKING TO SEE IF THE DATA WERE SUCCESSFULLY RECEIVED BY THE DATABASE OR NOT.if (mysqli_connect_errno()) {echo "The connection with the database failed." . mysqli_connect_error();exit();}// CLOSE THE RECORDmysqli_close($cxn);//DESTROY THE SESSION: THIS STATEMENT SHOULD APPEAR AT THE VERY END WHEN YOU HAVE STORED ALL THE FIELDS FOR A ROW IN THE DATABASEsession_destroy();?></body></html>\[/code\]
 
Top