chancellor Posted April 17, 2007 Share Posted April 17, 2007 I am new to PHP and am really struggling with PHP Session variables. On the first page I start with this: session_start(); $_SESSION['valid']=1; $test=$_POST['emailaddress']; $_SESSION["user"]=$test; in which the email address of the user will be posted on the previous page. In the next page, I attempt to put that user id into a database and it doesn't work: <?php session_start(); if(array_key_exists('page', $_POST) == FALSE) { $page = 0; } else { $page = $_POST['page']; } $db_name="histotec_db2"; $table_name="tabchapter2questions"; $connection=mysql_connect("localhost","histotec_","4chance"); $db=mysql_select_db($db_name,$connection); $sql="select questionanswer from tabchapter2questions where questionnumber=". $page; $result=mysql_query($sql,$connection); if(!$result) mysql_error(); while ($row=mysql_fetch_array($result, MYSQL_NUM)) { foreach($row as $v); } if ($_POST["question"]!=$v){ print"<'color:red'>wrong answer";} else { $page=$page+1; } $sql1="insert into tabchapter2usertracking (user,guess,questionnum) values('{$_SESSION['user']}','$_POST[question]',{$page})"; $result=mysql_query($sql1,$connection); ?> What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/47452-php-session-variables/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.