Jump to content

Recommended Posts

  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

I tried implementing a session but it won't send the variable over when submitted. So I get echo '$a'; is displaying as $EditThisItemType (just that and not the contents).

Ā 

<?php
session_start();

//get current type selected
$a = $_GET['EditThisItemType'];

// store session data
$_SESSION['Type']=$a;

$Submit = $_POST['SubmitB'];
$ItemType = $_POST['ItemType'];

echo $_GET['EditThisItemType'];

if ($_POST['SubmitB'] == "Submit")
{
echo '1';
$Valid_form = true;
$Valid_ItemType = true;

Ā  Ā  Ā   if (empty($ItemType))
Ā  Ā  Ā   {
 echo '2';
Ā  Ā  Ā  Ā   ?>
 <div style="position:absolute; top:220px; left:200px; width:550px">Ā   
	Ā  <span class="errmsg">Please Enter an Item Type</span>
 </div>
 <?phpĀ  Ā   
	$Valid_form = false;
	$Valid_ItemType = false;
}Ā  Ā   
else
Ā  Ā  Ā  Ā  { 
Ā  Ā  Ā  Ā  Ā  Ā   echo '3<br>';
Ā  Ā  Ā  Ā  Ā  Ā   echo "Current Item Type is". $_SESSION['Type'];
Ā  Ā  Ā  Ā  Ā  Ā   echo "<br>";
Ā  Ā  Ā  Ā  Ā  Ā   echo "$ItemType is new Item Type<br>";
Ā  Ā  Ā  Ā  Ā  Ā   $b = $_SESSION['Type'];
Ā  Ā  Ā  Ā  Ā  Ā  Ā  
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   $conn = mysql_connect('host:port','username','password');
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   $db = mysql_select_db('dbname', $conn);
	 $sqlUpdate = "UPDATE ItemType SET ItemType = '$ItemType' WHERE ItemType ='$b'";
	 $rsUpdate = mysql_query($sqlUpdate,$conn) or die('Problem with query: ' . $sqlUpdate . '<br />' . mysql_error());	
	 $affectedrows = mysql_affected_rows($conn);
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   echo "$sqlUpdate is sqlUpdate<br>";
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   echo "$rsUpdate is rsUpdate<br>";

Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   echo "$affectedrows is number of affected rows<br>";

Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   if(mysql_affected_rows($conn) == "1") {
	Ā  Ā  echo '4';
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  $Edited = true;
		$NotExec = false;
	 }
	 elseif(mysql_affected_rows($conn) == "0"){
	Ā  Ā  echo '5';	
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  $Edited = false;
		$NotExec = true;
		?>
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   <div style="position:absolute; top:250px; left:200px; width:550px">Ā   
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   <span class="errmsg">Could not be edited, <?php echo "$ItemType";?> may already exist!</span>
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   </div>
		<?phpĀ  Ā   

	 }
	 mysql_close($conn);
}
}
else
{
Ā  Ā  Ā  Ā  Ā  Ā   echo '6';	 
Ā  Ā  Ā  Ā  Ā  Ā   $EditThisItemType = $_SESSION['Type'];
}
?>

<html>
<head>
Ā   <title>Clothing Line</title>
Ā   <link href="stylesheetCL.css" rel="stylesheet">
Ā   <?php require('jscript.inc') ?>
Ā   
Ā   <?php if($NotExec == false && $Edited == true)
Ā   {

Ā  Ā  Ā  session_destroy();

Ā   ?>
Ā  Ā  Ā  <meta HTTP-EQUIV="REFRESH" content="0; url=display_item_types.php?Action=Edit&Edited=$Edited&NotExec=$NotExec">
Ā   <?php
Ā   }
Ā   ?>
</head>
<body>


<div style="position:absolute; top:75px; left:200px; width:550px">

<?php
if($_POST['SubmitB'] == "Submit")
{
?>
<span class="head3">Edit Form for Item Type: <?php echo $_SESSION['Type'] ?></span>
<br>
<br>

<?php
}
if($_POST['SubmitB'] !="Submit")
{
?>
<span class="head3">Edit Form for Item Type: <?php echo $EditThisItemType?></span>
<br>
<br>

<?php
}
?>


<form method="post" action='edit_item_type_form.php'/>

<?php
if($Valid_ItemType == false and $_POST['SubmitB'] == "Submit")
{
?>
<span class="errmsg">! </span>
<?php
}
?>

Item Type: <input type="text" name="ItemType" value="
<?php 
if($_POST['SubmitB'] == "Submit")
{

echo $_POST['ItemType']?>"/>
<?php
}

if($_POST['SubmitB'] != "Submit")
{
echo $EditThisItemType ?>"/>
<?php
}
?>

<input type="submit" name="SubmitB" value="Submit"/>
</form>Ā  

<br>
<br>
<br>
<br>
<a href="display_item_types.php?Action=Edit">Back to Edit Item Types List</a>
</div>

</body>
</html>

Ā 

So my outputs when submitting are:

Ā 

1
3
Current Item Type is
One Piece is new Item Type
UPDATE ItemType SET ItemType = 'One Piece' WHERE ItemType ='' is sqlUpdate
1 is rsUpdate
0 is number of affected rows
5

just try echo the session straight after the session is set also echo $a to ensure the variable is set.

Ā 

also

Ā 

change

Ā 

Ā   echo "$ItemType is new Item Type<br>";

Ā 

to

Ā 

Ā   echo $ItemType "is new Item Type<br>";

Ā 

Ā 

Ā 

Okay new edits have been made for verification, I have the outputs for before submission (when page is first loaded), and outputs after submission.

Ā 

Current code:

<?php
session_start();

//get current type selected
$a = $_GET['EditThisItemType'];

echo "Session Variable A is ". $a;
echo "<br>";

// store session data
$_SESSION['Type']=$a;

echo "Current Item Type is ". $_SESSION['Type'];
echo "<br>";

$Submit = $_POST['SubmitB'];
$ItemType = $_POST['ItemType'];

if ($_POST['SubmitB'] == "Submit")
{
echo '1';
echo"<br>";
$Valid_form = true;
$Valid_ItemType = true;

Ā  Ā  Ā   if (empty($ItemType))
Ā  Ā  Ā   {
 echo '2';
Ā  Ā  Ā  Ā   ?>
 <div style="position:absolute; top:220px; left:200px; width:550px">Ā   
	Ā  <span class="errmsg">Please Enter an Item Type</span>
 </div>
 <?phpĀ  Ā   
	$Valid_form = false;
	$Valid_ItemType = false;
}Ā  Ā   
else
Ā  Ā  Ā  Ā  { 
Ā  Ā  Ā  Ā  Ā  Ā   echo '3<br>';
Ā  Ā  Ā  Ā  Ā  Ā   echo "Session Type is now ". $_SESSION['Type'];
Ā  Ā  Ā  Ā  Ā  Ā   echo "<br>";
Ā  Ā  Ā  Ā  Ā  Ā   echo "New Item Type is now ". $ItemType;
Ā  Ā  Ā  Ā  Ā  Ā   echo "<br>";
Ā  Ā  Ā  Ā  Ā  Ā   $b = $_SESSION['Type'];
Ā  Ā  Ā  Ā  Ā  Ā  Ā  
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   $conn = mysql_connect('host:port','username','password');
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   $db = mysql_select_db('dbname', $conn);
	 $sqlUpdate = "UPDATE ItemType SET ItemType = '$ItemType' WHERE ItemType ='$b'";
	 $rsUpdate = mysql_query($sqlUpdate,$conn) or die('Problem with query: ' . $sqlUpdate . '<br />' . mysql_error());	
	 $affectedrows = mysql_affected_rows($conn);
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   echo "$sqlUpdate is sqlUpdate<br>";
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   echo "$rsUpdate is rsUpdate<br>";

Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   echo "$affectedrows is number of affected rows<br>";

Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   if(mysql_affected_rows($conn) == "1") {
	Ā  Ā  echo '4';
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  $Edited = true;
		$NotExec = false;
	 }
	 elseif(mysql_affected_rows($conn) == "0"){
	Ā  Ā  echo '5';	
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  $Edited = false;
		$NotExec = true;
		?>
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   <div style="position:absolute; top:250px; left:200px; width:550px">Ā   
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   <span class="errmsg">Could not be edited, <?php echo "$ItemType";?> may already exist!</span>
Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā   </div>
		<?phpĀ  Ā   

	 }
	 mysql_close($conn);
}
}
else
{
Ā  Ā  Ā  Ā  Ā  Ā   echo '6';	 
Ā  Ā  Ā  Ā  Ā  Ā   $EditThisItemType = $_SESSION['Type'];
}
?>

<html>
<head>
Ā   <title>Clothing Line</title>
Ā   <link href="stylesheetCL.css" rel="stylesheet">
Ā   <?php require('jscript.inc') ?>
Ā   
Ā   <?php if($NotExec == false && $Edited == true)
Ā   {

Ā  Ā  Ā  session_destroy();

Ā   ?>
Ā  Ā  Ā  <meta HTTP-EQUIV="REFRESH" content="0; url=display_item_types.php?Action=Edit&Edited=$Edited&NotExec=$NotExec">
Ā   <?php
Ā   }
Ā   ?>
</head>
<body>


<div style="position:absolute; top:75px; left:200px; width:550px">

<?php
if($_POST['SubmitB'] == "Submit")
{
?>
<span class="head3">Edit Form for Item Type: <?php echo $_SESSION['Type'] ?></span>
<br>
<br>

<?php
}
if($_POST['SubmitB'] !="Submit")
{
?>
<span class="head3">Edit Form for Item Type: <?php echo $EditThisItemType?></span>
<br>
<br>

<?php
}
?>


<form method="post" action='edit_item_type_form.php'/>

<?php
if($Valid_ItemType == false and $_POST['SubmitB'] == "Submit")
{
?>
<span class="errmsg">! </span>
<?php
}
?>

Item Type: <input type="text" name="ItemType" value="
<?php 
if($_POST['SubmitB'] == "Submit")
{

echo $_POST['ItemType']?>"/>
<?php
}

if($_POST['SubmitB'] != "Submit")
{
echo $EditThisItemType ?>"/>
<?php
}
?>

<input type="submit" name="SubmitB" value="Submit"/>
</form>Ā  

<br>
<br>
<br>
<br>
<a href="display_item_types.php?Action=Edit">Back to Edit Item Types List</a>
</div>

</body>
</html>


Ā 

First Output (Looks good)

Variable One Pieces is One Pieces
Current Item Type is One Pieces
6

Ā 

Secondary Output (Missing values for $a and subsequently for $_Session['Type']

Session Variable A is
Current Item Type is
1
3
Session Type is now
New Item Type is now One Piece
UPDATE ItemType SET ItemType = 'One Piece' WHERE ItemType ='' is sqlUpdate
1 is rsUpdate
0 is number of affected rows
5

I get these messages:

Ā 

Notice: Undefined index: SubmitB in /home/www/psychowolvesbane.freehostia.com/admin/edit_item_type_form.php on line 18

Ā 

Notice: Undefined index: ItemType in /home/www/psychowolvesbane.freehostia.com/admin/edit_item_type_form.php on line 19

Ā 

Notice: Undefined index: SubmitB in /home/www/psychowolvesbane.freehostia.com/admin/edit_item_type_form.php on line 21

6

Notice: Undefined variable: NotExec in /home/www/psychowolvesbane.freehostia.com/admin/edit_item_type_form.php on line 91

Ā 

Notice: Undefined variable: Edited in /home/www/psychowolvesbane.freehostia.com/admin/edit_item_type_form.php on line 91

Ā 

Notice: Undefined index: SubmitB in /home/www/psychowolvesbane.freehostia.com/admin/edit_item_type_form.php on line 108

Ā 

Notice: Undefined index: SubmitB in /home/www/psychowolvesbane.freehostia.com/admin/edit_item_type_form.php on line 117

Edit Form for Item Type: One Pieces

Ā 

Ā 

Notice: Undefined variable: Valid_ItemType in /home/www/psychowolvesbane.freehostia.com/admin/edit_item_type_form.php on line 132

Ā 

Notice: Undefined index: SubmitB in /home/www/psychowolvesbane.freehostia.com/admin/edit_item_type_form.php on line 132

Sorry that was what errors occur before submission, which some are fine since they are only used once submission is done thus an error is reported.

Ā 

the errors I get once submitted are:

Ā 

Ā 

Notice: Undefined index: EditThisItemType in /home/www/psychowolvesbane.freehostia.com/admin/edit_item_type_form.php on line 7

Session Variable A is

Current Item Type is

1

3

Session Type is now

New Item Type is now dgdsg

UPDATE ItemType SET ItemType = 'dgdsg' WHERE ItemType ='' is sqlUpdate

1 is rsUpdate

0 is number of affected rows

5

No that didn't work, the Session is set fine before submission but the value gets lost in translation once the form is submitted, is there any line I need to add to the page address in the form action line to send the Session data over?

The site host is freehostia.com, my browser is Mozilla Firefox 2.0.0.11, I don't have any special restrictions or connections that I am aware of, and the same goes for Internet Explorer 7. I don't know specifically where to look in my cpanel but I'll try to find some stats that will help.

<?php
error_reporting(E_ALL);
session_start();

//get current type selected
$a = $_GET['EditThisItemType'];

echo "Session Variable A is ". $a;
echo "<br>";

$_SESSION['Type'] = true;

// store session data
$_SESSION['Type']=$a;
?>

change to

<?php
error_reporting(E_ALL);
session_start();

//get current type selected
$a = $_GET['EditThisItemType'];

// store session data
$_SESSION['Type']=$a;

echo $_SESSION['Type'];
echo $a;

What is the output. I thing you are not understanding how sessions work.

?>

Ā 

No, I'm notĀ  :'(

Ā 

Anyway, I get

Ā 


Notice: Undefined index: EditThisItemType in /home/www/psychowolvesbane.freehostia.com/admin/edit_item_type_form.php on line 6


1
3
Session Type is now
New Item Type is now One Piece
UPDATE ItemType SET ItemType = 'One Piece' WHERE ItemType ='' is sqlUpdate
1 is rsUpdate
0 is number of affected rows
5

Ā 

Which doesn't display anything for either of the Session variables 'Type' or '$a'.

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.