Jump to content

Please help passing variable


lingo5

Recommended Posts

Hi,

I am trying to pass a variable when posting a form.

This is my form with the select:

<form id="form1" name="form1" method="post"  action="products_2.php?id_subcategoria= WHAT SOULD I PUT HERE?">
<select name="subcats" class="subcatsSelectMenu" id="subcats" onchange="this.form.submit()">
<option value="">Ver placas por tipos</option>
<?php
do {  
?>
<option value="<?php echo $row_subcats_RS['id_subcategoria']?>"><?php echo $row_subcats_RS['subcategoria_esp']?></option>
<?php
} while ($row_subcats_RS = mysql_fetch_assoc($subcats_RS));$rows = mysql_num_rows($subcats_RS);
  if($rows > 0) {
      mysql_data_seek($subcats_RS, 0);
  $row_subcats_RS = mysql_fetch_assoc($subcats_RS);
  }
?>
</select>
</form>

How can I pass the variable in the URL?

Thanks

Link to comment
Share on other sites

Rather than attempting to change the the action section of the form and passing value as get, just pick up posted value at the top of your page and use that variable for calling records etc.

<?php
if (isset($_POST['subcats'])){
$id_subcategoria=$_POST['subcats'];
}
?>
<html>
<body>
<form id="form1" name="form1" method="post"  action="products_2.php">
<select name="subcats" class="subcatsSelectMenu" id="subcats" onchange="this.form.submit()">
<option value="">Ver placas por tipos</option>
<?php
do {  
?>
<option value="<?php echo $row_subcats_RS['id_subcategoria']?>"><?php echo $row_subcats_RS['subcategoria_esp']?></option>
<?php
} while ($row_subcats_RS = mysql_fetch_assoc($subcats_RS));$rows = mysql_num_rows($subcats_RS);
  if($rows > 0) {
      mysql_data_seek($subcats_RS, 0);
  $row_subcats_RS = mysql_fetch_assoc($subcats_RS);
  }
?>
</select>
</form>

Link to comment
Share on other sites

Oh. I didn't realize we were dealing with different pages.  Is there any reason the processing needs to be on a different page?  You could always use a header("location: ")  if you must, but I would just have the posted values process on the page where it will be used.

 

 

Link to comment
Share on other sites

The reason why I'm going to a different page is because I have a recordset in the curret page that selects items by id_category like so:

mysql_select_db($database_MySQLconnect, $MySQLconnect);
$query_productos_RS = sprintf("SELECT * FROM t_articulo WHERE id_categoria = %s", GetSQLValueString($colname_productos_RS, "int"));
$query_limit_productos_RS = sprintf("%s LIMIT %d, %d", $query_productos_RS, $startRow_productos_RS, $maxRows_productos_RS);
$productos_RS = mysql_query($query_limit_productos_RS, $MySQLconnect) or die(mysql_error());
$row_productos_RS = mysql_fetch_assoc($productos_RS);

So I dont know how to set the same page up to use your method.

Link to comment
Share on other sites

I think the easiest way would be to pass the variable from page A to page B.

Could I do something like this?

action="productos_2.php?id_subcategoria=<?php echo((isset($_POST["subcats"]))?$_POST["subcats"]:"") ?>">

...please help!!

Link to comment
Share on other sites

Yes, never having used sprintf() or GetSQLValueString(), or understanding the reason for using them I can't help with that directly.  However as you seem to need values passed as GET, then just use the header as I mentioned, adding this to the top of your products.php page.  Be sure to change your forms to post to this page as well.

<?php

if (isset($_POST['subcats'])){

$id_subcategoria=$_POST['subcats'];

header ("location: productos_2.php?id_subcategoria=$id_subcategoria");

exit;

}

?>

Link to comment
Share on other sites

Man I feel silly missing this.  I guess it's because I never use GET in a form.  Why not just change the form to...

 

<form id="form1" name="form1" method="get"  action="products_2.php">
<select name="id_subcategoria" class="subcatsSelectMenu" id="subcats" onchange="this.form.submit()">
<option value="">Ver placas por tipos</option>
<?php
do {  
?>
<option value="<?php echo $row_subcats_RS['id_subcategoria']?>"><?php echo $row_subcats_RS['subcategoria_esp']?></option>
<?php
} while ($row_subcats_RS = mysql_fetch_assoc($subcats_RS));$rows = mysql_num_rows($subcats_RS);
  if($rows > 0) {
      mysql_data_seek($subcats_RS, 0);
  $row_subcats_RS = mysql_fetch_assoc($subcats_RS);
  }
?>
</select>
</form>

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.