Jump to content

SESSION VARIABLES (PHP Version 5.2.4)


cdub1885

Recommended Posts

I'm setting up a user input form with session variables.  The values get dropped from

one page to another and the first page is haveing trouble resetting the variable.

As you can see I'm using an array $v[]

????

Are my arrays set correctly.  Do I have to set a variable in php.ini?

I do not want to turn of globals.

 

 

<?php
// paqe 1  = index.php
include 'db.php';
session_start();
$v = array();
$_SESSION[$v];	
$v[0] = "Recipe Name";          $v[1]= "Catagory";      $v[2]= "Source";       $v[3]= "Special Materials"; $v[4]= "Ingredients";   $v[5]= "Instructions";
echo "varray debug <br / >";
print_r($v);

?>
<html> 
<meta http-equiv="Refresh" Content = "1; url = textinput.php">
<head><title> index </title></head>
<body></body> 
</html>
end of page 1

start of page 2
<?php
// page 2 = textinput.php"
session_start();
$inputs = array();
for ($i = 0; $i < 6; $i++){
	$inputs[$i] = $_SESSION[$v[$i]];
}
echo "inputs array debug <br / >";
print_r($inputs);
echo "<br />";

echo "v array debug <br / >";
print_r($inputs);
echo "<br />";


?>

<html>
<head><title>Text Input</title>
<link rel="stylesheet" href="nav_style.css" type="text/css"></head>
<br /><br />
<a href = "index.php">[ RESET DEBUG ]</a>
<form method="post" action="textcheck.php?submit=no">
<input type=submit value= "REVIEW YOUR INPUTS"></td>
INPUTS	<br />

<! input # 0>
Line 1: 
<input type="text" size=30 name="line1" value = "<?=$inputs[0]?>">
<br />	
<! input # 1>
Line 2: 
<input type="text" size=30 name="line2" value = "<?=$inputs[1]?>">
<br />	
<! input # 2>
Line 3: 
<input type="text" size=30 name="line3" value = "<?=$inputs[2]?>">
<br />
<! input # 3>
Text Area 1:
<textarea name="textarea1" rows="20" cols="80" >
<?=$inputs[3]?>

</textarea>
<br />
<! input # 4>
Text Area 2:
<textarea name="textarea2" rows="10" cols="80" >
<?=$inputs[4]?>

</textarea>
<br />
<! input # 5>
Text Area 3:
<textarea name="textarea3" rows="10" cols="80" >
<?=$inputs[5]?>

</textarea>
<br />
</form>
<form method="post">

</form> 
</body>
</html>
end of page 2

start of page 3 check the data  = textcheck.php
<?php
//include 'db.php';
//include 'error.php';
session_start();

if ($_GET[submit] == "insert")
{

$connection = mysql_connect("localhost",$user,$pass);
mysql_select_db("web", $connection);
$sql = "insert into teachers values (";
    		$sql .= $data_sql;
    		$sql .= ");";	

	$result = @ mysql_query ($sql,$connection)
		or showerror();

	mysql_close();

echo "<h1>Your inputs have been submitted.<br>";
echo "<h3>sql code: $sql";


}else{

$v[0] = $_POST["line1"];
$v[1] = $_POST["line2"];
$v[2] = $_POST["line3"];
$v[3] = $_POST["textarea1"];
$v[4] = $_POST["textarea2"];
$v[5] = $_POST["textarea3"];

echo "varray DEBUG <br / >";
print_r($v);
$_SESSION['t']    = time();

$data_sql = "'-1'" ;
$data_sql .= ",'$v[0]','$v[1]','$v[2]','$v[3]','$v[4]','$v[5]','$v[6]','$v[7]','$v[8]'";

echo "SQL $sql_data";
}



?>
<html><head><title> title </title></head>
<body bgcolor = "silver">

<?if ($_GET[submit] != "insert")
{
?>
<FORM method="post" action="textcheck.php?submit=insert">
<input type="submit" value="SUBMIT YOUR INPUTS">


</form>

<?}?>
<br />

<a href = "textinput.php?d=$v">[ BACK TO INPUTS ]</a>
<br />
Line 1:
<?=$v[0]; ?>
<br />
Line 2:
<?=$v[1];?>
<br />

Line 3:
<pre>
<?=$v[2]; ?>
</pre>
<br />
Line 4:
<pre>
<?=$v[3]; ?>
</pre>
<br />


Line 5:
<pre>
<?=$v[4]; ?>
</pre>
<br />

Line 6:
<pre>
<?=$v[5]; ?>
</pre>
<br />


</body>
</html>



Link to comment
https://forums.phpfreaks.com/topic/90679-session-variables-php-version-524/
Share on other sites

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.