dprichard Posted June 4, 2007 Share Posted June 4, 2007 I can't figure out what I am doing wrong here but any help would be greatly appreciated. I am trying to set a session variable along with my insert statement but on the next page when I do my query I get no results even though I know there are. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add_folder")) { $doc_cat_id = $_POST['folder_doc_cat']; session_register("doc_cat_id"); $insertSQL = sprintf("INSERT INTO folders (folder_name, folder_creator, folder_status, folder_order, folder_description, folder_doc_cat) VALUES (%s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['folder_name'], "text"), GetSQLValueString($_POST['folder_creator'], "int"), GetSQLValueString($_POST['folder_status'], "int"), GetSQLValueString($_POST['folder_order'], "int"), GetSQLValueString($_POST['folder_description'], "int"), GetSQLValueString($_POST['folder_doc_cat'], "int")); Then on my next page I have the query based off of the session variable, but I don't get anything back. $colname_folders = "-1"; if (isset($_POST['doc_cat_id'])) { $colname_folders = $_POST['doc_cat_id']; } $colname2_folders = "-1"; if (isset($_SESSION['doc_cat_id'])) { $colname2_folders = $_SESSION['doc_cat_id']; } mysql_select_db($database_ttracker, $ttracker); $query_folders = sprintf("SELECT * FROM folders_main WHERE folder_doc_cat = %s OR folder_doc_cat = %s ORDER BY folder_order ASC", GetSQLValueString($colname_folders, "int"),GetSQLValueString($colname2_folders, "text")); $folders = mysql_query($query_folders, $ttracker) or die(mysql_error()); $row_folders = mysql_fetch_assoc($folders); $totalRows_folders = mysql_num_rows($folders); Quote Link to comment https://forums.phpfreaks.com/topic/54170-problem-with-session-variable-and-passing-variable-on-insert/ Share on other sites More sharing options...
dprichard Posted June 4, 2007 Author Share Posted June 4, 2007 Bump Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/54170-problem-with-session-variable-and-passing-variable-on-insert/#findComment-267850 Share on other sites More sharing options...
kael.shipman Posted June 4, 2007 Share Posted June 4, 2007 Have you checked your php.ini configuration for register_globals? The documentation for the session_register() function (http://us.php.net/manual/en/function.session-register.php) says that this is necessary for the function to work and that the default value after 4.2 is OFF. You may want to simply switch over to use of the $_SESSION global array, which is not subject to those configuration settings and is the "preferred" method as of 4.1. Also, are you actually using that query that you wrote out using sprintf()? I don't see where it actually gets inserted into a sql call. I'm sure that's an abbreviated example, but I just wanted to make sure. Along those lines, are you setting the session variable "doc_cat_id" to anything? I'm starting to think maybe I'm not reading this right.... And what do you mean by "next page?" Is the bottom code block just an include in the top one, or is it literally the next page that the user loads? Of course, for that you'd need to put both your doc_cat_id AND insertSQL into session variables ($_SESSION['doc_cat_id'] = $doc_cat_id and $_SESSION['insertSQL'] = $insertSQL), though I don't know why these would actually be on separate pages. Maybe you could clarify your situation a bit more...? Quote Link to comment https://forums.phpfreaks.com/topic/54170-problem-with-session-variable-and-passing-variable-on-insert/#findComment-267857 Share on other sites More sharing options...
dprichard Posted June 4, 2007 Author Share Posted June 4, 2007 Here is my insert: if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add_folder")) { $folder_doc_cat = $_POST['folder_doc_cat']; session_register("folder_doc_cat"); $insertSQL = sprintf("INSERT INTO folders (folder_name, folder_creator, folder_status, folder_order, folder_description, folder_doc_cat) VALUES (%s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['folder_name'], "text"), GetSQLValueString($_POST['folder_creator'], "int"), GetSQLValueString($_POST['folder_status'], "int"), GetSQLValueString($_POST['folder_order'], "int"), GetSQLValueString($_POST['folder_description'], "int"), GetSQLValueString($_POST['folder_doc_cat'], "int")); mysql_select_db($database_ttracker, $ttracker); $Result1 = mysql_query($insertSQL, $ttracker) or die(mysql_error()); $insertGoTo = "documents_folders.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } And here is my query on the page that it post to after the insert: $colname_folders = "-1"; if (isset($_POST['doc_cat_id'])) { $colname_folders = $_POST['doc_cat_id']; } $colname2_folders = "-1"; if (isset($_SESSION['folder_doc_cat'])) { $colname2_folders = $_SESSION['folder_doc_cat']; } mysql_select_db($database_ttracker, $ttracker); $query_folders = sprintf("SELECT * FROM folders_main WHERE folder_doc_cat = %s OR folder_doc_cat = %s ORDER BY folder_order ASC", GetSQLValueString($colname_folders, "int"),GetSQLValueString($colname2_folders, "int")); $folders = mysql_query($query_folders, $ttracker) or die(mysql_error()); $row_folders = mysql_fetch_assoc($folders); $totalRows_folders = mysql_num_rows($folders); It is PHP 5 and Register Globals is off. Quote Link to comment https://forums.phpfreaks.com/topic/54170-problem-with-session-variable-and-passing-variable-on-insert/#findComment-267862 Share on other sites More sharing options...
kael.shipman Posted June 4, 2007 Share Posted June 4, 2007 Hm. All I can think of is maybe it's being set, but there's something weird with the query. Have you tried echoing $query_folders (on the second page) to see what the actual query looks like? If you do that and it looks fine, try copyin the echoed query string and running it on your mysql client. If indeed your variable isn't set, see if it works to set it with $_SESSION['folder_doc_cat']. I hate to push that so much, but the documentation does say that session_register() is deprecated, so you may as well get in the habit of using $_SESSION[]. Remember to call session_start() before trying to use $_SESSION, though, as the call is not implicit when using the variable. Quote Link to comment https://forums.phpfreaks.com/topic/54170-problem-with-session-variable-and-passing-variable-on-insert/#findComment-267906 Share on other sites More sharing options...
trq Posted June 4, 2007 Share Posted June 4, 2007 I don't see any call to session_start() in either of your pages. Also, session_register has long been deprecated and should no longer be used. You really ought to learn and write your own php instead of letting Dreamweaver do it for you... honestly, that is some of the most disorganized / hard to read code Ive seen. Not to mention the fact that it uses deprecated functionality. Quote Link to comment https://forums.phpfreaks.com/topic/54170-problem-with-session-variable-and-passing-variable-on-insert/#findComment-267911 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.