paradoxmime Posted January 6, 2010 Share Posted January 6, 2010 I have this code that allows me to update my database. But after updating, I lose the $_GET['page'] value in the browser. I need this value because it is passed when I go to other pages on the site. echo ($_GET['change'] == 'Garage_Type') ? '<form method="get" action="' . $_SERVER['PHP_SELF'] . '"> <select name="Garage_Type"> <option value="Attached">Garage </option> <option value="Detached">Detached Garage </option> <option value="Attached Carport">Carport </option> <option value="Detached Carport">Detached Carport </option> <option value="None">None </option> </select> <input type="submit" name="submit" value="Update DB!" /><input type="hidden" name="id" value="' . $this->_ID . '" /><input type="hidden" name="col" value="Garage_Type" /></form>' . '</td></tr></table></td></tr><tr><td colspan="3" bgcolor="#CCCCCC"></td></tr><tr><td>': $this->_DATA['Garage_Type'] . '</td></tr></table> </td><td><a href="' . $_SERVER['PHP_SELF'] . '?change=Garage_Type&id=' .$this->_ID .'&page='.$_GET['page'].'&orderid='.$_GET['orderid'].'&asc='.$_GET['asc'].'">Edit</a>' . '</td></tr><tr><td colspan="3" bgcolor="#CCCCCC">'; Quote Link to comment Share on other sites More sharing options...
paradoxmime Posted January 6, 2010 Author Share Posted January 6, 2010 In my file upload fields, it doesn't lose the page value. Here is the code for it: echo ($_GET['upload'] == 'Review_PDF') ? '<form method="post" enctype="multipart/form-data" action="' . $_SERVER['PHP_SELF'] . '?id=' . $this->_ID .'&page='.$_GET['page'].'&orderid='.$_GET['orderid'].'&asc='.$_GET['asc'].'"> <input name="Review_PDF" type="file" id="Review_PDF"> <input type="hidden" name="col" value="Review_PDF" /><input type="hidden" name="id" value="' . $this->_ID . '" /><input type="submit" value="Insert!" name="comsubmit" /></form></td></tr><tr><td>' : '<table width="200" align="left"><tr><td>NONE</td></tr></table></td><td><a href="' . $_SERVER['PHP_SELF'] . '?upload=Review_PDF&id=' . $this->_ID .'&page='.$_GET['page'].'&orderid='.$_GET['orderid'].'&asc='.$_GET['asc'].'">Insert Record to DB</a>' . '</td></tr><tr><td colspan="3" bgcolor="#000000" height="1"></td></tr><tr><td>'; Quote Link to comment Share on other sites More sharing options...
paradoxmime Posted January 6, 2010 Author Share Posted January 6, 2010 This is the error I get. "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/orderho1/public_html/userpanel.php on line 340" Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted January 6, 2010 Share Posted January 6, 2010 Update your form action: echo ($_GET['change'] == 'Garage_Type') ? '<form method="get" action="' . $_SERVER['PHP_SELF'] . '?page=' . $_GET['page'] . '"> You can see that the second form you posted passes the page in action="" along with some other variables. Quote Link to comment Share on other sites More sharing options...
paradoxmime Posted January 6, 2010 Author Share Posted January 6, 2010 I've already tried that and it doesn't work. Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted January 6, 2010 Share Posted January 6, 2010 I take it $_GET['change'] does actually equal 'Garage_Type' so that form is actually called? Load the page then check the source code, scroll down to where this form is and make sure that it has ?page=ID in the action. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted January 6, 2010 Share Posted January 6, 2010 post your query. the error you're receiving is from an error in your mysql query. and you say you lose it after updating. to keep use of 'page', you must continue to pass 'page' from page to page. perhaps if i see your query i will have a better understanding what you are doing (or not doing). Quote Link to comment Share on other sites More sharing options...
paradoxmime Posted January 6, 2010 Author Share Posted January 6, 2010 mysql_select_db('TGC'); if($_GET["asc"]==1) $ord="asc"; else $ord="desc"; /* For ordering by */ switch($_GET['orderid']) { case 1: $orderby = "Public $ord"; break; case 2: $orderby = "Plan_Number $ord"; break; case 3: $orderby = "Sq_Feet $ord"; break; case 4: $orderby = "Date_Added $ord"; break; case 5: $orderby = "Date_Modded $ord"; break; case 6: $orderby = "Rating $ord"; break; case 7: $orderby = "Sales_PDF $ord"; break; default: $orderby = "Plan_Number asc"; } $SQL = "SELECT Plan_ID, Public, Plan_Number, Sq_Feet, Elevation, Date_Added, Date_Modded, Sales_PDF, Garage_Location, User_Rating,Sold FROM House_Plans WHERE Des_ID = '$this->_ID' and Deleted<>1 ORDER BY $orderby"; if(!isset($_GET["page"])){ $page = 1; } else { $page = $_GET["page"]; } // Define the number of results per page $max_results = 10; // Figure out the limit for the query based // on the current page number. $from = (($page * $max_results) - $max_results); // Perform MySQL query on only the current page number's results $result = mysql_query($SQL." LIMIT $from, $max_results"); // Figure out the total number of results in DB: $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM House_Plans WHERE Des_ID = '". $this->_ID ."'"),0); //code to find online and offline plans $sql_number="SELECT Public FROM House_Plans WHERE Des_ID = '". $this->_ID ."'"; $sql_query=mysql_query($sql_number); while($sql_res=mysql_fetch_array($sql_query)) { if($sql_res["Public"]==1) $m++; else $k++; } Quote Link to comment Share on other sites More sharing options...
paradoxmime Posted January 6, 2010 Author Share Posted January 6, 2010 Can you see why one will work and the other will not? Quote Link to comment Share on other sites More sharing options...
paradoxmime Posted January 7, 2010 Author Share Posted January 7, 2010 Is this what you were asking for? Quote Link to comment Share on other sites More sharing options...
paradoxmime Posted January 7, 2010 Author Share Posted January 7, 2010 Any help on this is greatly appreciated! I have thousands of records in the DB to modify via my php page and having my issue resolved will eliminate countless hours of additional work Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted January 8, 2010 Share Posted January 8, 2010 Is it possible for you to post the entire page's code? It's hard to see where errors occur when just getting segments as they might not be where the issue is. If you don't want to post it you can always PM it to me. Quote Link to comment Share on other sites More sharing options...
paradoxmime Posted January 8, 2010 Author Share Posted January 8, 2010 The page has a lot of code so I will tell you which lines to look at... Look at the very bottom. Notice the "Begin Review" area? This is a file upload form that works fine. All the file uploads work. When I say 'works', I mean that after entering data or uploading afile, I am still able to click the "back to user panel" link where it takes me back to the userpanel and everything displays correctly. That is because the"page=" passes a value that userpanel can use to determine what to show. Then scroll up til you see if (!empty($this->_DATA['Plan_Description'])) This form and all the others above it do not pass the page= value. Now I know that currently it shows '<form method="get" action="' . $_SERVER['PHP_SELF'] . '"> and does not include the '?id=' . $this->_ID .'&GP_upload=1&page='.$_GET['page'].'&orderid='.$_GET['orderid'].'&asc='.$_GET['asc']. I have tried this and it still does not work. I am missing something somewhere [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted January 8, 2010 Share Posted January 8, 2010 I'm sorry but I can't help. I think what you're missing is a bit of organisation, that file is a mess - sorry but there's no other word for it. It's no doubt a bit late to go back and re-think the structuring of the page but sometimes it's needed. If you've added the necessary get variables to the form action and it isn't working, then I think that's as far as I can help you anyway. It would take too long for me to understand how your code flows, only you know that. The only thing I can suggest is this: add the necessary ?id & page= etc to the form action, load the page (but don't submit). Check the source code (right-click view source) and see whether the form action has the correct values in it. Quote Link to comment Share on other sites More sharing options...
paradoxmime Posted January 8, 2010 Author Share Posted January 8, 2010 I can see how things may seem confusing. I have deleted everything that doesn't matter or apply to the situation. I left anything that might be needed. Don't pay any attention to the <td><tr> tags that might be missing. I have attached the file. Please look again and see if it's easier for you this time. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
paradoxmime Posted January 9, 2010 Author Share Posted January 9, 2010 Figured it out myself. Actually a friend pointed it out to me. I just added this to the form <input type="hidden" name="page" value="' . $_GET['page'] . '" /> That was all it took! Quote Link to comment 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.