Jump to content

Recommended Posts

Hi guys,

 

I need your help. How do I store data during a usersession in his userrow in mysql. I have a survey over three pages. The data needs to be saved after the user presses "continue" to get to the next page. Each page has 10 questions and the values for each questions are between 0 and five. The questions are divided in three different categories. So the results needed to be saved according the categories. The results always needs to be added in the mysql cell.  I am grateful for any (good) hints! Thanks!!

 

Link to comment
https://forums.phpfreaks.com/topic/153936-store-data-during-session/
Share on other sites

Sessions are not permament.

As they rely on a cookie PHPSESSID

without the cookie, there is no session data

 

Even tho sessions are stoed in a database, don't rely on them to hold valid info for more than the current session (if the user does have cookies enabled).

 

Hi laffin. the data needs to be stored in mysql forever. but the input comes during the users session (it is a secure site where he needed to log on). so when he comes next time and logs onto the site he needs to see the data which was stored last time)

 

so to make the challenge clear. User x logs onto my site ( his name is at that point alrady stored in the database. He fills out at survey which values need to be added to his rwo in cell x. they need to be stored there forever. How can I do that?

Im still a noob, but wont the following work:

 

in your user table you add a COLUMN for the USER_ID, now make a seperate table for storing the answers to which ever survey, and add along the USER_ID. and then when you want to show the results you just reach the survey table for 'blabla' WHERE user_id =......

OK... I really hope you can help me.. Ok I have got the login page (1.code) from there the users come on the intro page (2nd code) from there will be a link to the psychological test (to get the programming right I just wrote a table) (3rd code) to make it work.

My database is guntmar, table is users. the rows are resultspo, resultsmo and passion. The test has three pages (the submit button leads always to the next page, and at the same time the values should be stored in the mysql in the row of the user who is doing the test, so he can see it at anytime when he logs in again). The result of checkbox po, po1, etc.. need to be added in row resultspo, the results, mo, mo1, etc.. need to be added to row resultsmo, the results p, p1, etc.. need to be saved in row passion.

How can I do that??

 

<?php require_once('Connections/Login.php'); ?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "intro.php";
$MM_redirectLoginFailed = "login.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_Login, $Login);

$LoginRS__query=sprintf("SELECT firstname, name, results, username, password FROM users WHERE username='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 



$LoginRS = mysql_query($LoginRS__query, $Login) or die(mysql_error());
$row = mysql_fetch_array($LoginRS);          // ADDED
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
  $loginStrGroup = "";
  //declare two session variables and assign them
  $_SESSION['MM_Username'] = $loginUsername;
  $_SESSION['MM_password'] = $row['password'];
  $_SESSION['MM_UserGroup'] = $loginStrGroup;   
  $_SESSION['MM_name'] = $row['name'];   // CHANGED 
  $_SESSION['MM_results'] = $row['results'];
  $_SESSION['MM_firstname'] = $row['firstname'];


if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
if(isset($_POST['remember'])){
     setcookie("cookname", $_SESSION['MM_username'], time()+60*60*24*100, "/");
     setcookie("cookpass", $_SESSION['MM_password'], time()+60*60*24*100, "/");
  }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style3 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
color: #000033;
}
#Layer1 {
position:absolute;
left:71px;
top:83px;
width:473px;
height:119px;
z-index:1;
}
#Layer2 {
position:absolute;
left:71px;
top:212px;
width:354px;
height:17px;
z-index:2;
}
.style5 {
font-size: 11px;
color: #000033;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-style: italic;
}
#Layer3 {
position:absolute;
left:110px;
top:23px;
width:245px;
height:19px;
z-index:3;
}
#Layer4 {
position:absolute;
left:71px;
top:17px;
width:235px;
height:19px;
z-index:3;
}
#Layer5 {
position:absolute;
left:360px;
top:14px;
width:401px;
height:333px;
z-index:4;
}
-->
</style>
</head>
<body>
<div id="Layer1">
 <form action="<?php echo $loginFormAction; ?>" method="POST" name="form1" target="_top" id="form1">
   <table width="400" border="0" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF">
     <tr>
       <td width="100" class="style3">Username:</td>
       <td><div align="left">
           <input name="username" type="text" class="style3" id="username" />
       </div></td>
     </tr>
     <tr>
       <td width="100"><span class="style3">Password:</span></td>
       <td><div align="left">
           <input name="password" type="password" class="style3" id="password" />
       </div></td>
     </tr>
     <tr>
       <td class="style3">Remember me: </td>
       <td><input name="remember" type="checkbox" id="remember" value="checkbox" /></td>
     </tr>
     <tr>
       <td width="100"> </td>
       <td><div align="left">
           <input name="Submit" type="submit" class="style3" value="Submit" />
       </div></td>
     </tr>
   </table>
 </form>
</div>
<div class="style5" id="Layer2">If you don't have a login, please register <a href="register.php" target="_self">here</a>. </div>
<div id="Layer4"><a href="pics/buttonlogin.php"><img src="pics/buttonlogin.jpg" alt="" name="" width="257" height="19" border="0" /></a></div>
<div id="Layer5">
 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="400" height="325">
   <param name="flash_component" value="ImageViewer.swc" />
   <param name="movie" value="login.swf" />
   <param name="quality" value="high" />
   <param name="FlashVars" value="flashlet={imageLinkTarget:'_blank',captionFont:'Verdana',titleFont:'Verdana',showControls:true,frameShow:false,slideDelay:5,captionSize:10,captionColor:#333333,titleSize:10,transitionsType:'Random',titleColor:#333333,slideAutoPlay:false,imageURLs:['img1.jpg','img2.jpg','img3.jpg'],slideLoop:false,frameThickness:2,imageLinks:['http://macromedia.com/','http://macromedia.com/','http://macromedia.com/'],frameColor:#333333,bgColor:#FFFFFF,imageCaptions:[]}" />
   <embed src="login.swf" quality="high" flashvars="flashlet={imageLinkTarget:'_blank',captionFont:'Verdana',titleFont:'Verdana',showControls:true,frameShow:false,slideDelay:5,captionSize:10,captionColor:#333333,titleSize:10,transitionsType:'Random',titleColor:#333333,slideAutoPlay:false,imageURLs:['img1.jpg','img2.jpg','img3.jpg'],slideLoop:false,frameThickness:2,imageLinks:['http://macromedia.com/','http://macromedia.com/','http://macromedia.com/'],frameColor:#333333,bgColor:#FFFFFF,imageCaptions:[]}" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="400" height="325"> </embed>
 </object>
</div>
<div align="center"></div>
</body>
</html>

 

<?php
//initialize the session
if (!isset($_SESSION)) {
 session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
 $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
 //to fully log out a visitor we need to clear the session varialbles
 $_SESSION['MM_Username'] = NULL;
 $_SESSION['MM_UserGroup'] = NULL;
 $_SESSION['PrevUrl'] = NULL;
 unset($_SESSION['MM_Username']);
 unset($_SESSION['MM_UserGroup']);
 unset($_SESSION['PrevUrl']);

 $logoutGoTo = "http://www.guntmarwolff.com";
 if ($logoutGoTo) {
   header("Location: $logoutGoTo");
   exit;
 }
}
?>
<?php require_once('Connections/Login.php'); ?><?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
// For security, start by assuming the visitor is NOT authorized. 
$isValid = False; 

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
// Therefore, we know that a user is NOT logged in if that Session variable is blank. 
if (!empty($UserName)) { 
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
// Parse the strings into arrays. 
$arrUsers = Explode(",", $strUsers); 
$arrGroups = Explode(",", $strGroups); 
if (in_array($UserName, $arrUsers)) { 
$isValid = true; 
} 
// Or, you may restrict access to only certain users based on their username. 
if (in_array($UserGroup, $arrGroups)) { 
$isValid = true; 
} 
if (($strUsers == "") && true) { 
$isValid = true; 
} 
} 
return $isValid; 
}

$MM_restrictGoTo = "index.html";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo); 
exit;
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Intro</title>
<style type="text/css">
<!--
.style3 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
color: #000033;
}
.style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #000033; font-weight: bold; }
.style11 {color: #000033}
-->
</style>
</head>
<body>
<p> </p>
<table width="917" border="0">
 <tr>
   <td height="32" colspan="2" class="style8"> </td>
   <td class="style8"> </td>
   <td class="style8"> </td>
   <td class="style3"> </td>
   <td class="style3"> </td>
   <td class="style3"><div align="right"><span class="style8"><a href="<?php echo $logoutAction ?>"><img src="pics/logout.jpg" width="86" height="24" border="0" longdesc="http://www.guntmarwolff.com" /></a></span></div></td>
 </tr>
 <tr>
   <td height="32" colspan="2" class="style8"><span class="style8">
<script type="text/javascript">
/*<![CDATA[*/
	function clock()
	{
		//////////////////////////////////////////////////////
		//Coded by the notorious jackpf
		/////////////////////////////////////////////////////

		//generate time
		var time = new Date();
		var hours = time.getHours();
		var minutes = time.getMinutes();
		var seconds = time.getSeconds();

		//add preceding 0s, if required
		var hours = (hours < 10 ? '0' : '')+hours;
		var minutes = (minutes < 10 ? '0' : '')+minutes;
		var seconds = (seconds < 10 ? '0' : '')+seconds;

		//generate formated time
		var time = hours+':'+minutes+':'+seconds;

		//get where abouts in the day it is
		if(hours >= 0 && hours < 12)
		{
			var greeting = 'Good Morning';
		}
		if(hours >= 12 && hours < 18)
		{
			var greeting = 'Good Afternoon';
		}
		if(hours >= 18 && hours < 00)
		{
			var greeting = 'Good Evening';
		}

		//display time
		document.getElementById('clock').innerHTML = time+'<br />'+greeting;
	}
	//init clock
	window.onload = function()
	{
		clock();
		setInterval('clock()', 1000);
	}
/*]]>*/
</script>
<span id="clock"></span><?php echo " " .  $_SESSION['MM_firstname']; ?></span></td>
   <td width="71" class="style8"> </td>
   <td width="107" class="style8"> </td>
   <td class="style3"> </td>
   <td width="164" class="style3"><div align="left"><span class="style3"><?php echo "You are logged in as<br>"?><em><strong><?php echo $_SESSION['MM_Username']; ?></strong></em></span></div></td>
   <td width="163" class="style3"><span class="style11">
     <?php 
//This file shows you how to include the file in your php document.


include("online.php"); 
?>
   </span></td>
 </tr>
 <tr>
   <td colspan="2" class="style3"></td>
   <td colspan="2"> </td>
   <td width="125"> </td>
   <td valign="top"> </td>
   <td class="style3"> </td>
 </tr>
 <tr>
   <td width="95"> </td>
   <td width="162"> </td>
   <td colspan="2"> </td>
   <td> </td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
   <td colspan="2" rowspan="15"> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td> </td>
   <td> </td>
   <td colspan="2"> </td>
   <td> </td>
   <td> </td>
   <td> </td>
 </tr>
</table>
<p> </p>
<p> </p>
<p> <a href="<?php echo $logoutAction ?>"></a></p>
</body>
</html>

 

<?php require_once('Connections/Login.php'); ?>
<?php
mysql_select_db($database_Login, $Login);
$query_Recordset1 = "SELECT users.resultspo, users.resultsmo, users.resultspassion, users.results FROM users";
$Recordset1 = mysql_query($query_Recordset1, $Login) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
session_start();
$_SESSION['MM_passion'] = $po; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/JavaScript">
<!--
function MM_goToURL() { //v3.0
 var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
 for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
 <table width="667" border="1">
   <tr>
     <td>question one </td>
     <td width="210">passionorientation</td>
     <td width="346"><p>
       <label>
         <input type="radio" name="po" value="0" />
         0</label>
       <label>
       <input type="radio" name="po" value="1" />
1</label>
       <label>
       <input type="radio" name="po" value="2" />
2</label>
       <label>
       <input type="radio" name="po" value="3" />
3</label>
       <label>
       <input type="radio" name="po" value="4" />
4</label>
       <label>
       <input type="radio" name="po" value="5" />
5</label>
<br />
       <br />
     </p></td>
   </tr>
   <tr>
     <td> </td>
     <td>passion</td>
     <td><p>
       <label>
         <input type="radio" name="p" value="0" />
         0</label>
       <label>
       <input type="radio" name="p" value="1" />
1</label>
       <label>
       <input type="radio" name="p" value="2" />
2</label>
       <label>
       <input type="radio" name="p" value="3" />
3</label>
       <label>
       <input type="radio" name="p" value="4" />
4</label>
       <label>
       <input type="radio" name="p" value="5" />
5</label>
<br />
     </p></td>
   </tr>
   <tr>
     <td height="34"> </td>
     <td>motivation</td>
     <td></label>
       <input type="radio" name="m" value="0" />
0
</label>
<label>
<input type="radio" name="m" value="1" />
1</label>
<label>
<input type="radio" name="m" value="2" />
2</label>
<label>
<input type="radio" name="m" value="3" />
3</label>
<label>
<input type="radio" name="m" value="4" />
4</label>
<label>
<input type="radio" name="m" value="5" />
5</label></td>
   </tr>
   <tr>
     <td height="34"> </td>
     <td>passionorientation</td>
     <td></label>
       <input type="radio" name="po1" value="0" />
0
</label>
<label>
<input type="radio" name="po1" value="1" />
1</label>
<label>
<input type="radio" name="po1" value="2" />
2</label>
<label>
<input type="radio" name="po1" value="3" />
3</label>
<label>
<input type="radio" name="po1" value="4" />
4</label>
<label>
<input type="radio" name="po1" value="5" />
5</label></td>
   </tr>
   <tr>
     <td height="34"> </td>
     <td>passion</td>
     <td></label>
       <input type="radio" name="p1" value="0" />
0
</label>
<label>
<input type="radio" name="p1" value="1" />
1</label>
<label>
<input type="radio" name="p1" value="2" />
2</label>
<label>
<input type="radio" name="p1" value="3" />
3</label>
<label>
<input type="radio" name="p1" value="4" />
4</label>
<label>
<input type="radio" name="p1" value="5" />
5</label></td>
   </tr>
   <tr>
     <td height="34"> </td>
     <td>motivation</td>
     <td></label>
       <input type="radio" name="m1" value="0" />
0
</label>
<label>
<input type="radio" name="m1" value="1" />
1</label>
<label>
<input type="radio" name="m1" value="2" />
2</label>
<label>
<input type="radio" name="m1" value="3" />
3</label>
<label>
<input type="radio" name="m1" value="4" />
4</label>
<label>
<input type="radio" name="m" value="5" />
5</label></td>
   </tr>
   <tr>
     <td width="89" height="34"> </td>
     <td colspan="2"><p align="center">
       <input name="Submit" type="submit" onclick="MM_goToURL('parent','testtestpage2.php');return document.MM_returnValue" value="Submit" />
     </p>        </td>
   </tr>
 </table>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.