Log in

View Full Version : Getting a var in a URL



pavmoxo
07-07-2006, 04:02 PM
Hi!!!

I have a problem with getting a variable if I try to insert a new subcategory:



<? if ($_POST["nova_subcat"] != "Nova...") {?>

<select name="subcat_ID" id="subcat_ID" tabindex="3">
<?
$sql = "select s.subcat_ID, s.subcat_nome, c.cat_nome from subcat_links s, cat_links c where s.cat_ID=c.cat_ID and c.cat_ID=".$_GET["cat"]." order by s.subcat_nome" ;
$queryl = query($sql);
$contal = mysql_num_rows($queryl);
for ($j=0;$j<$contal;$j++)
{
$arrl = mysql_fetch_array($queryl);
?>

<option value="<?php echo $arrl["subcat_ID"]; ?>"><?php echo $arrl["subcat_nome"]; ?></option>
<? } ?>

</select>

<input name="nova_subcat" type="submit" value="Nova...">
<input name="del_subcat" type="submit" value="Apagar">
<? } else { ?>
<input name="subcat_nome" type="text" class="frm1" id="subcat_nome" size="10">
<input name="insert_subcat" type="submit" value="Inserir">
<? } ?>
URL before I click Nova...

...links.php?cat=16

After:

...links.php

Beginning of the form:

<form action="links.php" method="post" enctype="multipart/form-data" name="links">

Function to insert a new subcategory:



if ($_POST["insert_subcat"] == "Inserir")
{
$sql = "insert into subcat_links values(NULL,'".$_POST["subcat_nome"]."', '".$_POST["cat_ID"]."')";
$query = query($sql);
if ($query == 1)
{
echo "<script>alert('A subcategoria foi introduzida com sucesso.');</script>";
echo "<meta http-equiv=\"refresh\" content=\"0;URL=links.php?cat=".$_POST["cat_ID"]."\">";
}
else
{
echo "<script>alert('Problemas na inserção da subcategoria.');</script>";
echo "<meta http-equiv=\"refresh\" content=\"0;URL=links.php?cat=".$_POST["cat_ID"]."\">";
}
}

What should I do to remain with the URL for insert a subcategory??

eamon
07-09-2006, 11:06 PM
try putting a hidden field in and carry the value that way so use the $_POST instead e.g


<input type=hidden value=<yourvaluehere> name=subcatergory >

you mite want to do some conditioning here befor you do the header
e.g
<? if($_POST['subcatergory']) {
header("location: links.php?sub=$_POST['subcatergory']"); } else { exit; } ?>