![]() |
sponsored links |
|
|
sponsored links
|
|
|
14
17th March 01:35
External User
Posts: 1
|
Wow,
Thank you! You appear to have gotten me 90% towards my mission final. mysql_select_db($database_ftn, $ftn); @extract($_POST); $query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range = '$select1'"; echo $query_Recordset1; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $ftn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); <form id="form1" name="form1" method="post" action="index_dev.php"> <label>market <select name="select1"> <OPTION value="1">Indiana</OPTION> <OPTION value="2">Wisconsin</OPTION> <OPTION value="3">Illinois</OPTION> <OPTION value="4">Michigan</OPTION> <OPTION value="5">Ge****a</OPTION> <OPTION value="6">Florida</OPTION> </select> <input name="submit" type="submit" value="post"/> </label> </form> Works!!!!!!!!!!!!! Thank you! Thank you! Thank you! Sincerely, Brad -----Original Message----- From: Jim Lucas [mailto:lists@cmsws.com] Sent: Tuesday, June 12, 2007 1:57 PM To: BSumrall Cc: php-general@lists.php.net Subject: Re: [php] Looking for help with forms/variables and an array! if this is within PHP, the '{' and '}' are within double quotes (which they seem to be), These examples should all do the same thing. $query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range = '$select1'"; $query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range = '{$select1}'"; $query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range = '".$select1."'"; echo $query_Recordset1; place an echo just after including the variable and see if you see the brackets in the statement. -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare |
|
|
15
17th March 01:35
External User
Posts: 1
|
I, I, sir!
I changed it back! )Point noted! -----Original Message----- From: Robert ***mings [mailto:robert@interjinn.com] Sent: Tuesday, June 12, 2007 1:24 PM To: BSumrall Cc: php-general@lists.php.net Subject: RE: [php] Looking for help with forms/variables and an array! That's no excuse... and you're wrong. Ok... and magic_quotes? You don't seem to be escaping your data that goes into the query either. You don't seem very "aware of the security risk". Why do it twice? Why risk forgetting something after the fact? Coding securely requires that you practice coding securely and not just hope you can apply a coat of armorall afterwards. The same tools I have, if not then you have more. I gave you an example at the bottom of my post. Are you passing the $query string directly to the mysql_query() function? Maybe do the following just before running the query: echo $query."\n"; Then check it to see that it's what you expect. Cheers, Rob. -- ..------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' |
|
|
17
17th March 01:35
External User
Posts: 1
|
I thank you kindly for your pointers.
It did really help me with getting further. Persons like yourself are truly talented to be able and bang out the theory like that on the fly. Only problem is that I am using php to learn code for the first real time. The Microsoft stuff started to throw me off. I am going sit hear and study your example intently and hopefully it will clue me off on my major variable error. I am right there with it! Brad -----Original Message----- From: Dan Shirah [mailto:mrsquash2@gmail.com] Sent: Tuesday, June 12, 2007 3:05 PM To: Jim Lucas Cc: BSumrall; php-general@lists.php.net Subject: Re: [php] Looking for help with forms/variables and an array! Wouldn't a little javascript solve this problem?? Have your first dropdown menu, then when an option is selected use a javascript Onchange function to refresh (post) the page to itself. This would set the selected option as your "form1" value. Then just write a simple query using that value to return the options you want for dropdown #2. Something like this: <select name="states" onchange="this.submit();"> <option value="AL" > Alabama <option value="FL" >Florida <option value="WA" >Washington <option value="MI" >Michigan </select> if (!isset($_POST['submit'])) { $state = $_POST['states']; Then put your result in an array and populate your second dropdown. <td width="43" align="right">City:</td> <td width="135" align="left" class="tblcell_sm"> <SELECT name="city"> <?php $database = mssql_select_db("database", $connection) or die ('DB selection failed'); // Query the table and load all of the records into an array. $q_cities = "SELECT * FROM cities WHERE state_name = '$state'"; $r_cities = mssql_query($q_cities) or die(mssql_error()); while ($rec_cities = mssql_fetch_assoc($r_cities)) $c_city[] = $rec_cities; echo "<OPTION value=\"\">--SELECT--</OPTION>\n"; foreach ($c_city as $s_city) { if ($s_city['state_name'] == $_POST['states']) echo "<OPTION value=\"{$s_city['city_code']}\" SELECTED>{$s_city['city_name']}</OPTION>\n"; else echo "<OPTION value=\"{$s_city['city_code']}\">{$s_cc['city_name']}</OPTION>\n"; } ?> </SELECT> </td> Hope that helps?? lol |
|
|
19
17th March 01:36
External User
Posts: 1
|
I had done that before,
But here it goes again because I have learned a little bit more -> establish db connect -> drop down box stores result as a variable -> first initial query performed -> query array established -> drop down box 2 is saved as a variable -> variable 2 filters query 1 -> display one record at a time Here is what I have right now. It is error free, just doest work, all I have done change some variables and not even bothering with record set 2 yet Anything in bold is what I have played with since it would pull every record, just not filter and now does not work. Brad <?php require_once('connections/ftn.php'); ?> <?php $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Recordset1 = 1; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_ftn, $ftn); @extract($_POST); $query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range = '$state'"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $ftn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; $queryString_Recordset1 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Recordset1") == false && stristr($param, "totalRows_Recordset1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1); ?> <body> <form id="form1" name="form1" method="post" action="index_dev2.php"> <label>market <select name="states"> <OPTION value="IN">Indiana</OPTION> <OPTION value="WI">Wisconsin</OPTION> <OPTION value="IL">Illinois</OPTION> <OPTION value="MI">Michigan</OPTION> <OPTION value="GA">Ge****a</OPTION> <OPTION value="FL">Florida</OPTION> </select> </label> </form> <?php if ($states=="value" || !isset($states)) echo "selected"; ?> <br> <form id="form2" name="form2" method="post" action="index_dev2.php"> <label>price_range <select name="price"> <OPTION value="1">Over $2 million</OPTION> <OPTION value="2">$1 million - $2 million</OPTION> <OPTION value="3">$750,000 - $1 million</OPTION> <OPTION value="4">under $750,000</OPTION> </select> <input name="submit" type="submit" value="post"/> </label> </form> <?php if ($price=="value"|| !isset($price)) echo "selected"; ?> <?php do { ?> -----Original Message----- From: Jim Lucas [mailto:lists@cmsws.com] Sent: Tuesday, June 12, 2007 8:26 PM To: BSumrall Cc: php-general@lists.php.net Subject: Re: [php] Looking for help with forms/variables and an array! Are you wanting to setup some sorta pagination, or just get the results from the DB limited by the selected option in the form? oh, where is your second form in this example? In pseudo code, write out what you are attempting to do? -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare |
|