adam291086 Posted January 2, 2008 Share Posted January 2, 2008 also use this siteĀ http://www.w3schools.com/php/php_sessions.asp and php.net Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428051 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428063 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 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>"; Ā Ā Ā Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428078 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428151 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 where is the first output results coming from? Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428156 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 put this at the top of the page to look for errors Ā <?php error_reporting(E_ALL); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428158 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428159 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428174 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 it seems the session is not being set. Ā Try setting session to $_SESSION['Type'] = true; Ā and see what happens Ā Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428184 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428189 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 when the session is set that should be stores on the clients computer until destroyed. Look at your browser settings. is the site hosted remotely. If so let me have a look at whats going on. Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428192 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428204 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 whats your url so i can have a look. I am still learning php so bear with me Ā Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428205 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 http://psychowolvesbane.freehostia.com Ā It's a work in progress as half of the stuff isn't made yet, I have another page on the go but I want this problem out of the way first. Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428207 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 try doing a simple session setting through the url. Then call on that session from a different page. Get that working and then intergrate it into your code. Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428209 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 I tried putting in: Ā <form method="post" action='edit_item_type_form.php?' . SID . ''/> Ā But it didn't work, am I doing this right? Ā Ā Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428218 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 show me the part where you are setting the session Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428219 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 <?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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428222 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 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. ?> Ā Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428226 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 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'. Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428231 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 you are sure the url has EditThisItemType in it Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428234 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 Take a look for yourself, http://psychowolvesbane.freehostia.com/admin/edit_item_type_form.php?EditThisItemType=One%20Pieces Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428237 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 it is echoing correctly. LOL. Look in the top left cornor it say what the url EditThisItemType is set to. Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428245 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 I know! It just won't play ball and send the info over through the submit! Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428246 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 right so whats on that line 6 where the error is once submit is clicked Quote Link to comment https://forums.phpfreaks.com/topic/83879-solved-mysql-update-query-problem/page/2/#findComment-428249 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.