gw32 Posted July 26, 2011 Share Posted July 26, 2011 I need to pass the variable "directory" along with $id. But the more I try the more errors I get, can some one please point me in the correct direction? echo "<form method=post name=f1 action='somefile.php'>"; echo "<select name='first' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($var2 = mysql_fetch_array($quer2)) { if($var2['DID']==@$id){echo "<option selected value='$var2[DID]'>$var2[directory]</option>"."<BR>";} else{echo "<option value='$var2[DID]'>$var2[directory]</option>";} } echo "</select>"; This is my first attempt with multiple MySQL/PHP forms. This selects the "id" from the first table and submits it to a new drop down list using a second table. The $id passes fine but I also need the variable 'directory' as $path. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/ Share on other sites More sharing options...
marcelobm Posted July 26, 2011 Share Posted July 26, 2011 you could do something like: echo "<option value='$var2[DID]_$var2[directory]'>$var2[directory]</option>"; and then in the script that receives the value use $value_arr = explode("_",$value); and that will give you: $value_arr[0] = id; $value_arr[1] = path or directory]; That is the simple solution, the other solution is, when you get the id in the script that process the form, do a query with the id you get to retrieve the directory Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247276 Share on other sites More sharing options...
gw32 Posted July 26, 2011 Author Share Posted July 26, 2011 echo "<option value='$var2[DID]_$var2[directory]'>$var2[directory]</option>"; This would be fine, except that the $var2[directory] breaks the link to the next table lookup. I need it to look like this "firstfile.php?id=1" With your method it appears as "firstfile.php?id=1_pathname" and I get a data error. Here is the complete code for what I am trying to do. ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT directory, DID FROM directory order by directory"); /////// for second drop down list we will check if directory is selected else we will display all the names///// if(isset($id) and strlen($id) > 0){ $quer=mysql_query("SELECT DISTINCT name FROM images where DID=$id order by name"); }else{$quer=mysql_query("SELECT DISTINCT name FROM images order by name"); } echo "<form method=post name=f1 action='somefile.php'>"; ////////// Starting of first drop down list ///////// echo "<select name='id' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($var2 = mysql_fetch_array($quer2)) { if($var2['DID']==@$id){echo "<option selected value='$var2[DID]'>$var2[directory]</option>"."<BR>";} else{echo "<option value='$var2[DID]'>$var2[directory]</option>";} } echo "</select>"; ////////// Starting of second drop down list ///////// echo "<select name='name'><option value=''>Select one</option>"; while($var1 = mysql_fetch_array($quer)) { echo "<option value='$var1[name]'>$var1[name]</option>"; } echo "</select>"; echo "<input type=submit value=Submit>"; echo "</form>"; in somefile.php I have this: <body> <? $id=$_POST['id']; $image=$_POST['name']; $path=$_POST['path']; echo "Value of \$id = $id <br>Value of \$path = $path <br>Value of \$image = $image"; ?> As you can the path variable does not show up. I could possibly strip the path name from the second table lookup prior to doing the query. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247297 Share on other sites More sharing options...
AyKay47 Posted July 26, 2011 Share Posted July 26, 2011 I don't even see an input with the name of "path" in your code...how would you grab $_POST['path'] if it doesn't exist..? Unless i'm just missing it Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247299 Share on other sites More sharing options...
gw32 Posted July 26, 2011 Author Share Posted July 26, 2011 That was my original question, how do I pass the variable '$var2[directory]' from the first drop down list select statement? Sorry I made it look and sound more difficult than it was supposed to be. Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247303 Share on other sites More sharing options...
AyKay47 Posted July 26, 2011 Share Posted July 26, 2011 you could do something like: echo "<option value='$var2[DID]_$var2[directory]'>$var2[directory]</option>"; and then in the script that receives the value use $value_arr = explode("_",$value); and that will give you: $value_arr[0] = id; $value_arr[1] = path or directory; That is the simple solution, the other solution is, when you get the id in the script that process the form, do a query with the id you get to retrieve the directory why wouldn't this method work for you that he provided? echo "<option value='{$var2["DID"]}_{$var2["directory"]}'>{$var2["directory"]}</option>"; Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247309 Share on other sites More sharing options...
fenway Posted July 26, 2011 Share Posted July 26, 2011 I'm not sure why you have multiple values being passed here... what does each one represent? Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247312 Share on other sites More sharing options...
gw32 Posted July 26, 2011 Author Share Posted July 26, 2011 Because his solution, although is perfect for another program I am working on, would give me "firstfile.php?id=1_bridal" When the second sql statement reads $id it is looking for a number (1) the above is not in the table. the field in the table is DID (int, length 3). Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247332 Share on other sites More sharing options...
fenway Posted July 26, 2011 Share Posted July 26, 2011 I don't follow -- why do you need both/ Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247353 Share on other sites More sharing options...
AyKay47 Posted July 26, 2011 Share Posted July 26, 2011 Because his solution, although is perfect for another program I am working on, would give me "firstfile.php?id=1_bridal" When the second sql statement reads $id it is looking for a number (1) the above is not in the table. the field in the table is DID (int, length 3). if you are using it for a url then replace the "_" with a "&" Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247355 Share on other sites More sharing options...
gw32 Posted July 26, 2011 Author Share Posted July 26, 2011 nope didn't work, I'll try a different method. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247424 Share on other sites More sharing options...
AyKay47 Posted July 26, 2011 Share Posted July 26, 2011 yeah, i don't get how it get's from an option to a url...you never showed us that...So how can you expect us to help with something that is unclear..try a different method Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247426 Share on other sites More sharing options...
gw32 Posted July 26, 2011 Author Share Posted July 26, 2011 Sir; My code is this: ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT directory, DID FROM directory order by directory"); ////////// Starting of first drop down list ///////// echo "<select name='id' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($var2 = mysql_fetch_array($quer2)) { if($var2['DID']==@$id){echo "<option selected value='$var2[DID]'>$var2[directory]</option>"."<BR>";} else{echo "<option value='$var2[DID]'>$var2[directory]</option>";} } echo "</select>"; [/color] I have this as a passed variable "select name='id'" and also this "$var2['DID']==@$id". Now what I need to pass is this "$var2[directory]". So how do I do it in it's present context. The complete code is listed earlier. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247435 Share on other sites More sharing options...
wildteen88 Posted July 26, 2011 Share Posted July 26, 2011 So you want to retrieve both the $var2['DID'] and $var2['directory'] values from the <select></select> field when the form has been submitted? Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247437 Share on other sites More sharing options...
gw32 Posted July 26, 2011 Author Share Posted July 26, 2011 Yes Sir. Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247444 Share on other sites More sharing options...
wildteen88 Posted July 26, 2011 Share Posted July 26, 2011 The only way to pass both the $var2['DID'] and $var2['directory'] values would be as marcelobm suggested to you earlier you could do something like: echo "<option value='$var2[DID]_$var2[directory]'>$var2[directory]</option>"; and then in the script that receives the value use $value_arr = explode("_",$value); and that will give you: $value_arr[0] = id; $value_arr[1] = path or directory]; That is the simple solution, the other solution is, when you get the id in the script that process the form, do a query with the id you get to retrieve the directory To get the id and directory within the script that processes the form you'd use something like this list($id, $directory) = explode('_', $_POST['id']); Quote Link to comment https://forums.phpfreaks.com/topic/242840-pass-all-variables-from-mysqlphp-form/#findComment-1247450 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.