rondog Posted May 28, 2008 Share Posted May 28, 2008 I have two dropdowns in a form. I am just trying to echo out the data selected right now: <?php if(isset($_POST['savechanges'])) { echo $_POST['customertxt']."<br>"; echo $_POST['stateinput']."<br>"; echo $_POST['cityinput']."<br>"; } $query = mysql_query("SELECT * FROM de_dealers WHERE id = '".$_GET['storeID']."'") or die(mysql_error()); $content = "<fieldset><legend>You are editing inside of <b>".str_replace("_"," ",$_GET['c']).", ".str_replace("_"," ",$_GET['s'])."</b> | <a href=\"javascript:history.go(-1)\"><img src=\"../images/folderup.gif\" border=\"0\" /></a> | <a href=\"storeeditor.php\">Main</a></legend>"; $row = mysql_fetch_array($query); $curState = $row['state']; $curID = $row['id']; $content .= "<table><form name=\"sel\" method=\"POST\">\n"; $content .= "<tr><td>$status</td></tr>\n"; $content .= "<tr><td>Customer</td><td><input type=\"text\" name=\"customertxt\" id=\"textfield\" value=\"$row[customer]\" size=\"35\"/></td></tr>\n"; $content .= "<tr><td>State</td><td><font id=\"states\"><select name=\"stateinput\"><option value=\"$row[state]\">$row[state]</option></select></font></td></tr>\n"; $content .= "<tr><td>City</td><td><font id=\"cities\"><select name=\"cityinput\"><option value=\"$row[city]\">$row[city]</option></select></font></td></tr>\n"; $content .= "<tr><td colspan=\"2\"><div align=\"right\"><input name=\"savechanges\" type=\"submit\" value=\"Save Changes\"/></div></td></tr>\n"; $content .= "</form></table></fieldset>"; ?> customertxt is showing up, but state and city aren't (customertxt is just an input text field). I have a feeling it has something to do with the dropdowns being AJAX. Check this link out and view the source to see. Its not a lot of code at all. http://drewestate.com/new/2008/admin/storeeditor.php?s=California&c=Pasedena&storeID=112 Quote Link to comment https://forums.phpfreaks.com/topic/107567-menu-not-posting/ Share on other sites More sharing options...
roopurt18 Posted May 28, 2008 Share Posted May 28, 2008 Whenever you refer to associative array indexes, enclose the index in quotes. Use $array['index'], do not use $array[index]. Whenever you include a variable within a double quoted string, enclose it in curly brackets. Use echo "Hello, {$name}!", do not use echo "Hello, $name!" Putting it together: echo "Congratulations, {$players['mvp']}!" Quote Link to comment https://forums.phpfreaks.com/topic/107567-menu-not-posting/#findComment-551365 Share on other sites More sharing options...
rondog Posted May 28, 2008 Author Share Posted May 28, 2008 thanks for the tip roopurt, but it still doesnt work even after I did what you said: <?php if(isset($_POST['savechanges'])) { echo "{$_POST['customertxt']}<br>"; echo "{$_POST['stateinput']}<br>"; echo "{$_POST['cityinput']}<br>"; } $query = mysql_query("SELECT * FROM de_dealers WHERE id = '".$_GET['storeID']."'") or die(mysql_error()); $content = "<fieldset><legend>You are editing inside of <b>".str_replace("_"," ",$_GET['c']).", ".str_replace("_"," ",$_GET['s'])."</b> | <a href=\"javascript:history.go(-1)\"><img src=\"../images/folderup.gif\" border=\"0\" /></a> | <a href=\"storeeditor.php\">Main</a></legend>"; $row = mysql_fetch_array($query); $curState = $row['state']; $curID = $row['id']; $content .= "<table><form name=\"sel\" method=\"POST\">\n"; $content .= "<tr><td>{$status}</td></tr>\n"; $content .= "<tr><td>Customer</td><td><input type=\"text\" name=\"customertxt\" id=\"textfield\" value=\"{$row['customer']}\" size=\"35\"/></td></tr>\n"; $content .= "<tr><td>Address 1</td><td><input type=\"text\" name=\"address1txt\" id=\"textfield2\" value=\"{$row['street1']}\" size=\"35\"/></td></tr>\n"; $content .= "<tr><td>Address 2</td><td><input type=\"text\" name=\"address2txt\" id=\"textfield3\" value=\"{$row['street2']}\" size=\"35\"/></td></tr>\n"; $content .= "<tr><td>State</td><td><font id=\"states\"><select name=\"stateinput\"><option value=\"{$row['state']}\">{$row['state']}</option></select></font></td></tr>\n"; $content .= "<tr><td>City</td><td><font id=\"cities\"><select name=\"cityinput\"><option value=\"{$row['city']}\">{$row['city']}</option></select></font></td></tr>\n"; $content .= "<tr><td>Zip</td><td><input type=\"text\" name=\"ziptxt\" id=\"textfield4\" value=\"{$row['zip']}\" size=\"35\"/></td></tr>\n"; $content .= "<tr><td colspan=\"2\"><div align=\"right\"><input name=\"savechanges\" type=\"submit\" value=\"Save Changes\"/></div></td></tr>\n"; $content .= "</form></table></fieldset>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/107567-menu-not-posting/#findComment-551370 Share on other sites More sharing options...
roopurt18 Posted May 28, 2008 Share Posted May 28, 2008 Your form certainly looks correct. I suspect that: $row['state'] $row['city'] are empty and your echo's at the top are working but printing empty strings. Try using this to see what data is set in $_POST: echo '<pre style="text-align: left;">' . print_r( $_POST, true ) . '</pre>'; If $_POST has indexes named stateinput and cityinput then it's the $row[] data that is empty. If $_POST doesn't have those indexes set then something else is wrong. Quote Link to comment https://forums.phpfreaks.com/topic/107567-menu-not-posting/#findComment-551396 Share on other sites More sharing options...
rondog Posted May 29, 2008 Author Share Posted May 29, 2008 Hi roopurt, sorry for the delayed response. I did what you said and it appears that $_POST doesnt have those indexes like you said. I am almost positive it has something to do with it being ajax. Here is what printed: Array ( [customertxt] => Briar Rose Cigar & Tobacco Shop [address1txt] => 20700 South Avalon Blvd. [address2txt] => Suite 537 [ziptxt] => 90746 [savechanges] => Save Changes ) Here is my PHP page that the onChange event handler calls for those drop downs: <?php //set IE read from page only not read from cache include '../connect.php'; header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header ("Cache-Control: no-cache, must-revalidate"); header ("Pragma: no-cache"); header("content-type: application/x-javascript; charset=tis-620"); $data = $_GET['data']; $val = $_GET['val']; $id = $_GET['id']; //set database if ($data == "states") { // first dropdown echo "<select name=\"stateinput\" onChange=\"dochange('cities', this.value)\">\n"; echo "<option value='0'>Choose a State</option>\n"; $result = mysql_query("SELECT DISTINCT state FROM de_dealers ORDER BY state ASC"); while($row = mysql_fetch_array($result)){ if($row['state'] == $val) { echo "<option value=\"$row[state]\" selected>$row[state]</option> \n" ; } else { echo "<option value=\"$row[state]\">$row[state]</option> \n" ; } } } else if ($data == "cities") { // second dropdown echo "<select name=\"cityinput\" >\n"; echo "<option value='0'>Choose a City</option>\n"; $result = mysql_query("SELECT DISTINCT city FROM de_dealers WHERE state = '$val' ORDER BY city ASC"); $curCity = mysql_query("SELECT city FROM de_dealers WHERE id = '$id'"); $city = mysql_fetch_array($curCity); while($row = mysql_fetch_array($result)){ if($row['city'] == $city['city']) { echo "<option value=\"$row[city]\" selected>$row[city]</option> \n"; } else { echo "<option value=\"$row[city]\">$row[city]</option> \n"; } } } echo "</select>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/107567-menu-not-posting/#findComment-552307 Share on other sites More sharing options...
rondog Posted May 29, 2008 Author Share Posted May 29, 2008 any idea what else it can be? Quote Link to comment https://forums.phpfreaks.com/topic/107567-menu-not-posting/#findComment-552699 Share on other sites More sharing options...
rondog Posted May 29, 2008 Author Share Posted May 29, 2008 Quote Link to comment https://forums.phpfreaks.com/topic/107567-menu-not-posting/#findComment-552991 Share on other sites More sharing options...
roopurt18 Posted May 29, 2008 Share Posted May 29, 2008 I disabled Javascript in my browser and it works fine. In FF and using the Web Developer toolbar, I chose: View Source -> View Generated Source and your form looks like this: <form name="sel" method="post"></form> Which means that none of your inputs are actually in the form. I'm guessing that the browser is sending up all of the inputs that actually use an input tag in this case and ignoring the select tags. Basically, either your markup is screwed up or your JavaScript is screwing it up. Quote Link to comment https://forums.phpfreaks.com/topic/107567-menu-not-posting/#findComment-553024 Share on other sites More sharing options...
rondog Posted May 29, 2008 Author Share Posted May 29, 2008 Hmm thats strange, I see what you are talking about. I dont understand how its not putting it in the tags though because my form is obviously wrapped in form tags: <?php $content .= "<table><form name=\"sel\" method=\"POST\">\n"; $content .= "<tr><td>$status</td></tr>\n"; $content .= "<tr><td>Customer</td><td><input type=\"text\" name=\"customertxt\" id=\"textfield\" value=\"$row[customer]\" size=\"35\"/></td></tr>\n"; $content .= "<tr><td>State</td><td><font id=\"states\"><select name=\"stateinput\"><option value=\"$row[state]\">$row[state]</option></select></font></td></tr>\n"; $content .= "<tr><td>City</td><td><font id=\"cities\"><select name=\"cityinput\"><option value=\"$row[city]\">$row[city]</option></select></font></td></tr>\n"; $content .= "<tr><td colspan=\"2\"><div align=\"right\"><input name=\"savechanges\" type=\"submit\" value=\"Save Changes\"/></div></td></tr>\n"; $content .= "</form></table></fieldset>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/107567-menu-not-posting/#findComment-553030 Share on other sites More sharing options...
rondog Posted June 2, 2008 Author Share Posted June 2, 2008 any suggestions? ??? Quote Link to comment https://forums.phpfreaks.com/topic/107567-menu-not-posting/#findComment-555282 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.