Jump to content

Pass all variables from mysql/php form


gw32

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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 "&"

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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']);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.