Jump to content

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
https://forums.phpfreaks.com/topic/259822-please-help-passing-variable/
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>

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.

 

 

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.

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;

}

?>

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>

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.