Jump to content

stuck- filter query from $_POST var in same form


dflow

Recommended Posts

im a bit stuck

i want to filter a  query using a $_POST var in same form

 

for example

1. select dropdown is $_POST['CountryID']

i want to query

2.$CountryDetails = sprintf("SELECT * FROM country_list WHERE CountryID = $_POST['CountryID']);

and echo the result

 

am i missing something in my approach?

 

i assume you mean

$CountryDetails = sprintf("SELECT * FROM country_list WHERE CountryID = %d", $_POST['CountryID']);

well im a bit lazy using the dw recordset creator but that value is defined as "colname"

 

here is the code

[quote author=thorpe link=topic=283679.msg1345019#msg1345019 date=1263215149]
[quote]am i missing something in my approach?[/quote]

Wouldn't know without a description f the problem.
[/quote]
for example this code after submit doesnt save the value in the vairiable
so if i press submit i dont get a result
but if i press submit again the variable is echoed

my goal is to filter the country_list tbl and get the name filtered by the CountryID value selected
[code]
<?php $colname_RsCountryDetails = "-1";
if (isset($_POST['CountryID'])) {
  $colname_RsCountryDetails = $_POST['CountryID'];
}
mysql_select_db($database_international, $international);
$query_RsCountryDetails = sprintf("SELECT * FROM country_list WHERE CountryID = %s", GetSQLValueString($colname_RsCountryDetails, "int"));
$RsCountryDetails = mysql_query($query_RsCountryDetails, $international) or die(mysql_error());
$row_RsCountryDetails = mysql_fetch_assoc($RsCountryDetails);
$totalRows_RsCountryDetails = mysql_num_rows($RsCountryDetails);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>


<form method="POST">
<select name="CountryID">
  <option value="0">CountryName</option>
  <option value="8">France</option>
  <option value="13">Italy</option>
</select>
<input name="CountryName" type="hidden" value="<?php echo $row_RsCountryDetails['CountryName'];?>" />
<input name="" type="submit" />
</form>
<?php

$CountryName = $_POST['CountryName'];
echo $CountryName;

?>

</body>
</html>

 

Can you mark it as solved then (bottom left)

actually not right yet ;)

one last thing

i got the query to work with the post variable and echo the value in

the Country hidden field

now

i want to continue and set :

<input name="CountryName" type="hidden" value="<?php echo $row_RsCountryDetails['CountryName'];?>" />
<input name="" type="submit" />
</form>
<?php

$CountryName = $_POST['CountryName'];

?>

 

after i submit and look at the source code i see the

correct value in the hidden field but the variable isnt geting the value

 

which i want of use in an email confirmation sent to the customer

 

$_POST are set after the form is submitted.. so it won't be set!

other than that i have no idea what your asking! :shrug:

ill try to be clearer:

i  have a contact form that i  insert data and send a copy

to the customer

i have an include dropdown select file where i get:

$CountryID

with $_POST['CountryID'] i query $query_RsCountryDetails and NEED to get CountryName from the country_list

table

 

<?php $colname_RsCountryDetails = "-1";
if (isset($_POST['CountryID'])) {
  $colname_RsCountryDetails = $_POST['CountryID'];
}
mysql_select_db($database_international, $international);
$query_RsCountryDetails = sprintf("SELECT * FROM country_list WHERE CountryID = %s", GetSQLValueString($colname_RsCountryDetails, "int"));
$RsCountryDetails = mysql_query($query_RsCountryDetails, $international) or die(mysql_error());
$row_RsCountryDetails = mysql_fetch_assoc($RsCountryDetails);
$totalRows_RsCountryDetails = mysql_num_rows($RsCountryDetails);


?>

 

the result is that when after i press submit

i echo the CountryName BUT i need it to be passed to the

email in the subject line and the html body

 

here is a form that is sending an email but $CountryName is empty :confused:

 

<?php require_once('../Connections/international.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_RsCountryDetails = "-1";
if (isset($_POST['CountryID'])) {
  $colname_RsCountryDetails = $_POST['CountryID'];
}
mysql_select_db($database_international, $international);
$query_RsCountryDetails = sprintf("SELECT * FROM country_list WHERE CountryID = %s", GetSQLValueString($colname_RsCountryDetails, "int"));
$RsCountryDetails = mysql_query($query_RsCountryDetails, $international) or die(mysql_error());
$row_RsCountryDetails = mysql_fetch_assoc($RsCountryDetails);
$totalRows_RsCountryDetails = mysql_num_rows($RsCountryDetails);

$colname_RsRegionDetails = "-1";
if (isset($_POST['RegionID '])) {
  $colname_RsRegionDetails = $_POST['RegionID '];
}
mysql_select_db($database_international, $international);
$query_RsRegionDetails = sprintf("SELECT * FROM region_list WHERE RegionID = %s", GetSQLValueString($colname_RsRegionDetails, "int"));
$RsRegionDetails = mysql_query($query_RsRegionDetails, $international) or die(mysql_error());
$row_RsRegionDetails = mysql_fetch_assoc($RsRegionDetails);
$totalRows_RsRegionDetails = mysql_num_rows($RsRegionDetails);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test contact </title>
</head>

<body>


<form method="POST">
<?php require_once('include/dropdown.php'); ?>
<input name="CustomerEmail" type="text" value="" />
<input name="CountryName" type="hidden" value="<?php echo $row_RsCountryDetails['CountryName'];?>" />
<input name="" type="submit" />
</form>

</body>
</html>
<?php
mysql_free_result($RsCountryDetails);

mysql_free_result($RsRegionDetails);
?>
<?php
/* grabs the POST variables and puts them into variables that we can use */
$CountryName=$_POST['CountryName'];
$CustomerEmail=$_POST['CustomerEmail'];
?>
<?php 




?>
<?php
// multiple recipients
$to = $CustomerEmail;

// subject
$subject = "Party:".$CustomerLastName."_".$TotalNumber."_PAX_" .$CountryName."_".$CityName."_".$RegionName."_".$num_nights."_nights_".$DepartureDate."-".$ReturnDate;




// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

// Additional headers
$headers .= 'From: example <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";


// Mail it
// message
  
$message ='
<html  dir="rtl" lang="he">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>
</body>
</html>
';


  $email = $_REQUEST['CustomerEmail'] ;

  if (!isset($_REQUEST['CustomerEmail'])) {
    
   }
  elseif (empty($email)) {
    
  }
  else {
  $url_success = "";


echo("<meta http-equiv = refresh content=0;url=".$url_success.">");
   mail($to, $subject, $message, $headers); 

  }
?>

 

this is really annoying :(

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.