Results 1 to 2 of 2

Thread: Getting a var in a URL

  1. #1
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Getting a var in a URL

    Hi!!!

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


    PHP Code:
    <? 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:


    PHP Code:
    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??

  2. #2
    Join Date
    Jun 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    try putting a hidden field in and carry the value that way so use the $_POST instead e.g

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •