kyleldi Posted March 9, 2009 Share Posted March 9, 2009 So what i'm trying to do can't truly be that hard, but I can't get it to work. I'm trying to make a form post information to a database (which it does), then output the entered value into a url. Here's my code to see if I can get it to make sense. Form code: <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="driving_directions" target="_blank" class="directions-form" id="driving_directions"> The editFormAction is supposed to post to a db as I said, and forward to data.php?data= which it does, but it does not fill in the posted information. I created a recordset that's supposed to pull the most recent post to the db and display it, but I still get no results. Here's the code for that: $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "driving_directions")) { $insertSQL = sprintf("INSERT INTO driving_directions (from_addr) VALUES (%s)", GetSQLValueString($_POST['from_addr'], "text")); mysql_select_db($database_ldregister, $ldregister); $Result1 = mysql_query($insertSQL, $ldregister) or die(mysql_error()); $insertGoTo = "data.php?data=$fromaddress"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_ldregister, $ldregister); $query_rs_directions = "SELECT * FROM driving_directions WHERE from_addr = '$editFormAction'"; $rs_directions = mysql_query($query_rs_directions, $ldregister) or die(mysql_error()); $row_rs_directions = mysql_fetch_assoc($rs_directions); $totalRows_rs_directions = mysql_num_rows($rs_directions); $fromaddress = str_replace(" ","+",$row_rs_directions['from_addr']); ?> Any ideas? Thank You! Quote Link to comment https://forums.phpfreaks.com/topic/148608-solved-passing-a-variable/ Share on other sites More sharing options...
micah1701 Posted March 9, 2009 Share Posted March 9, 2009 I might just be confused at what you're trying to do.. but doesn't header(sprintf("Location: %s", $insertGoTo)); forward the user before you get to the part that creates the URL you want? $insertGoTo includes the value of the var $fromaddress, but you're not setting that value until the end so its blank. Quote Link to comment https://forums.phpfreaks.com/topic/148608-solved-passing-a-variable/#findComment-780397 Share on other sites More sharing options...
kyleldi Posted March 9, 2009 Author Share Posted March 9, 2009 Then I guess my question is how do I call for that value before sending the header? Quote Link to comment https://forums.phpfreaks.com/topic/148608-solved-passing-a-variable/#findComment-780401 Share on other sites More sharing options...
kyleldi Posted March 9, 2009 Author Share Posted March 9, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/148608-solved-passing-a-variable/#findComment-780528 Share on other sites More sharing options...
premiso Posted March 9, 2009 Share Posted March 9, 2009 $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "driving_directions")) { $insertSQL = sprintf("INSERT INTO driving_directions (from_addr) VALUES (%s)", GetSQLValueString($_POST['from_addr'], "text")); mysql_select_db($database_ldregister, $ldregister); $Result1 = mysql_query($insertSQL, $ldregister) or die(mysql_error()); $insertGoTo = "data.php?data=$fromaddress"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } } mysql_select_db($database_ldregister, $ldregister); $query_rs_directions = "SELECT * FROM driving_directions WHERE from_addr = '$editFormAction'"; $rs_directions = mysql_query($query_rs_directions, $ldregister) or die(mysql_error()); $row_rs_directions = mysql_fetch_assoc($rs_directions); $totalRows_rs_directions = mysql_num_rows($rs_directions); $fromaddress = str_replace(" ","+",$row_rs_directions['from_addr']); header(sprintf("Location: %s", $insertGoTo)); ?> Move the header after those statements? Quote Link to comment https://forums.phpfreaks.com/topic/148608-solved-passing-a-variable/#findComment-780560 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.