dflow Posted January 11, 2010 Share Posted January 11, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/188046-stuck-filter-query-from-_post-var-in-same-form/ Share on other sites More sharing options...
trq Posted January 11, 2010 Share Posted January 11, 2010 am i missing something in my approach? Wouldn't know without a description f the problem. Quote Link to comment https://forums.phpfreaks.com/topic/188046-stuck-filter-query-from-_post-var-in-same-form/#findComment-992730 Share on other sites More sharing options...
MadTechie Posted January 11, 2010 Share Posted January 11, 2010 i assume you mean $CountryDetails = sprintf("SELECT * FROM country_list WHERE CountryID = %d", $_POST['CountryID']); Quote Link to comment https://forums.phpfreaks.com/topic/188046-stuck-filter-query-from-_post-var-in-same-form/#findComment-992732 Share on other sites More sharing options...
dflow Posted January 11, 2010 Author Share Posted January 11, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/188046-stuck-filter-query-from-_post-var-in-same-form/#findComment-992750 Share on other sites More sharing options...
dflow Posted January 11, 2010 Author Share Posted January 11, 2010 ok i solved it "the simple things you get stuck on" Quote Link to comment https://forums.phpfreaks.com/topic/188046-stuck-filter-query-from-_post-var-in-same-form/#findComment-992841 Share on other sites More sharing options...
MadTechie Posted January 11, 2010 Share Posted January 11, 2010 Can you mark it as solved then (bottom left) Quote Link to comment https://forums.phpfreaks.com/topic/188046-stuck-filter-query-from-_post-var-in-same-form/#findComment-992874 Share on other sites More sharing options...
dflow Posted January 11, 2010 Author Share Posted January 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188046-stuck-filter-query-from-_post-var-in-same-form/#findComment-992933 Share on other sites More sharing options...
MadTechie Posted January 11, 2010 Share Posted January 11, 2010 $_POST are set after the form is submitted.. so it won't be set! other than that i have no idea what your asking! Quote Link to comment https://forums.phpfreaks.com/topic/188046-stuck-filter-query-from-_post-var-in-same-form/#findComment-993040 Share on other sites More sharing options...
dflow Posted January 12, 2010 Author Share Posted January 12, 2010 $_POST are set after the form is submitted.. so it won't be set! other than that i have no idea what your asking! 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 <?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 <info@example.com>' . "\r\n"; $headers .= 'Cc: info@example.com' . "\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 Quote Link to comment https://forums.phpfreaks.com/topic/188046-stuck-filter-query-from-_post-var-in-same-form/#findComment-993438 Share on other sites More sharing options...
MadTechie Posted January 12, 2010 Share Posted January 12, 2010 That's because you are not selecting a $CountryName isn't being set from ant database reference ie $CountryName=$row_RsCountryDetails['CountryName']; Quote Link to comment https://forums.phpfreaks.com/topic/188046-stuck-filter-query-from-_post-var-in-same-form/#findComment-993521 Share on other sites More sharing options...
dflow Posted January 12, 2010 Author Share Posted January 12, 2010 thanks i thought it would get it from the text file <input name="CountryName" type="hidden" value="<?php echo $row_RsCountryDetails['CountryName'];?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/188046-stuck-filter-query-from-_post-var-in-same-form/#findComment-993614 Share on other sites More sharing options...
MadTechie Posted January 12, 2010 Share Posted January 12, 2010 That value is empty until you post, then it will be set, but your need to post it again, so it makes sense to grab it from the database instead Quote Link to comment https://forums.phpfreaks.com/topic/188046-stuck-filter-query-from-_post-var-in-same-form/#findComment-993653 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.