www.webdeveloper.com
Results 1 to 3 of 3

Thread: Lost Variable

Hybrid View

  1. #1
    Join Date
    Oct 2013
    Posts
    28

    Lost Variable

    I need som help - I really cant see where I do the mistake!


    I have a page that loads its content using variable given in an URL like:

    PHP Code:
    editgallery.php?folder=big_fish&id=459 
    The webpage is a page where you can change the name, description etc. Click "Update" and the information is saved (this part works fine)

    When clicking "Update" the user should be taken back to the old URL where they came from like this:

    PHP Code:
    galleries.php?folder=big_fish 
    Im using the below code to send the user back to the old URL:

    PHP Code:
    header("Location: galleries.php?folder=".$folder."&id=".$id.""); 
    But the folder variable is not saved/remembered/transfered to the new URL. When I use the above the URL looks like:

    PHP Code:
    galleries.php?folder=&id=459 
    Means that folder variable is lost but the id is used correct. Why does the folder variable not work?

    The copleate code of the site looks like:
    PHP Code:
    <?
    include "../config.php";
    include 
    "session.php";

    if(!
    $_POST["submit"])
    {
    include 
    "header.php";
    $query mysql_query("select name, type, folder, description , displaydate from galleries where id = '".$_GET["id"]."' ");
    $row mysql_fetch_row($query);
    $name $row[0];
    $type $row[1];
    $folder $row[2];
    $description $row[3];
    $displaydate $row[4];
    ?>

    <form method="POST" action="<?=$_SERVER["PHP_SELF"]?>" name="myform" id="myform">
    <center><table width="<?=$setting["tablewidth"]?>" class="admintable" cellpadding="<?=$setting["cellpadding"]?>">
    <tr>
        <td class="adminheader" colspan="2">&nbsp;<b>Edit Gallery:</b></td>
    </tr>

            <tr>    
                <td class="admincell">&nbsp;Name:</td>
                <td class="admincell">
    <input type="text" name="name" value="<?=$name?>" size="40"></td>
    </tr>
            <tr>    
                <td class="admincell">&nbsp;Category:</td><td class="admincell">

    <?=$folder?>

    </td>
    </tr>
    <tr valign="top">
    <td class="admincell">&nbsp;Display Date:</td>
    <td class="admincell" align="">
        <input style="border-style:hidden" type="text" value="<?=$displaydate?>" id="from" id="<?php echo $_REQUEST["from"]; ?>" name="displaydate" size="40">
        (yyyymmdd - Like <?=date('Ymd');?> or <?=date('Y-m-d');?>)</td>
    </tr>
    <tr valign="top">
    <td class="admincell">&nbsp;Description:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td class="admincell">

    <textarea id="Enter you description of the photo set here" name="description"><?=$description?></textarea></td>
    <!-- http://ckeditor.com/ -->          
                <script>
                    CKEDITOR.replace( 'description' );
                </script>
    </tr>
    <tr>
    <td class="admincell" colspan="2"><input type="hidden" name="id" value="<?=$_GET["id"]?>"><center>
    <input type="submit" name="submit" value="Update"></center></td>
    </tr>

    </table></center>
    </form><center>
    <p>



    </table></center>

    <?
    include "footer.php";
    }
    else
    {

    mysql_query("update galleries set name = '".$_POST["name"]."', description = '".$_POST["description"]."' , displaydate = '" $_POST["displaydate"] . "' where id = '".$_POST["id"]."' ");

    header("Location: galleries.php?folder=".$folder."&id=".$id."");
    //header("Location: galleries.php?folder=".$_GET['folder']);
    //header("Location: galleries.php");
    }
    ?>
    Last edited by NogDog; 04-29-2014 at 09:07 AM. Reason: added missing closing [/php] tag

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,241
    You set $folder inside of the if block, but if you fall through to the else block where you make the header() call, it's not going to be defined.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Oct 2013
    Posts
    28
    Hmmm I see, but if I do like:

    <?
    include "footer.php";
    header("Location: galleries.php?folder=".$folder."&id=".$id."");
    }
    else
    {

    mysql_query("update galleries set name = '".$_POST["name"]."', description = '".$_POST["description"]."' , displaydate = '" . $_POST["displaydate"] . "' where id = '".$_POST["id"]."' ");

    }
    ?>
    then the page editgallery.php?folder=big_fish&id=416 just load the galleries.php?folder=big_fish&id=416 instantly ad the edit page dont show up.

    So what do I do then to keep the folder variable?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles