Jump to content

[SOLVED] Passing a Variable


kyleldi

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/148608-solved-passing-a-variable/
Share on other sites

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.

$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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.