Jump to content

unable to retrieve $_GET['id'] value


el-sid

Recommended Posts

hi, i am unable to retrieve the id from the $_GET variable. I am trying to update a table in a database with a specific id. The thing is, i can see the id on the address bar, but cannot retrieve it via $_GET

 

 

http://portal:8080/events/admin/editEvent.php?id=14

 

this is the code

 


<?php
require('../config.php');
//require('../NewsScript.php');
include ('../../lib/class.form.php');
include ('../../lib/Events.class.php');
include ('../../lib/class.upload.php');

session_start();
/**
* Here we have clicked the button to update our edited article
* We need to update it in the database
*/
if(!empty($_POST['caption'])) {


    $event = new Events();

    $uploadDir =  dirname(__FILE__) . "/images/";

        $tmpName = $_FILES['event_image']['tmp_name'];

        $ext = substr(strrchr($tmpName, "."), 1);

// make the random file name
        $randName = md5(rand() * time());

// and now we have the unique file name for the upload file
        $filePath = $uploadDir . $randName . '.' . $ext;

        $name = $randName . '.' . $ext;

        $file = new upload($_FILES['event_image']);

        $file->file_new_name_body = $name;
        $file->image_resize = true;
        $file->image_convert = gif;
        $file->image_x = 100;
        $file->image_y = 100;
        $file->process($uploadDir);

        $event->updateEvent($_GET['id'], $_POST['caption'], $_POST['content'],  $filePath );

        
    if($event->updateEvent($_GET['id'], $_POST['caption'], $_POST['content'],  $filePath )) {
        echo "Update complete!";

       echo "<br>";
        echo $_GET['id'] .  "<br>";
        echo $_POST['caption'] .  "<br>";

        echo $_POST['content'] ."<br>";

        echo $filePath;

    }
    else {

        echo "Update Error!";
        
    }

    exit();

}
else // page loads but form not submitted
{
    if(is_numeric($_GET['id'])) {
        $connection = mysql_connect($db_host, $db_user, $db_password)
                or die("Unable to connect to MySQL");

        mysql_select_db($db_name, $connection) or die("Unable to select DB!");
        $id = $_GET['id'];

        $result = mysql_query("SELECT * FROM event WHERE id = '$id'");
        $row = mysql_fetch_assoc($result);

        $caption =  $row['caption'];
        $content = $row['content'];

        mysql_close($connection);
    }
    else {

        echo "None numeric Value!";

    }
}

/**
* output our content
*
*/
function showContent() {
    global $content;
    echo $content;
}

/**
* output the author
*
*/
function showCaption() {
    global $caption;
    echo 'value="'. $caption . '"';
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Edit News</title>
    </head>

    <body>
        <h1>Edit News</h1>
        <?php

        $form = new genForm();
        $form->startForm(basename($_SERVER['PHP_SELF']));

        $form->startFieldset('');
        $form->textareaInput('caption','Caption',false,false,false,$caption, 15,10);
        $form->closeFieldset();
        $form->insertBR();

        $form->startFieldset('');
        $form->textareaInput('content','Content',false,false,false,$caption, 25,10);
        $form->closeFieldset();
        $form->insertBR();

        $form->startFieldset('');
        $form->fileInput('event_image','Upload Your Event Picture');
        $form->closeFieldset();
        $form->insertBR();

        $form->newline = false;
        $form->submitButton();
        $form->newline = true;
        $form->resetButton();

        $form->closeForm();

        if(!$output = $form->getForm()) {
            die("error: " . $form->error);
        }
        else {
            echo $output;
        }

        ?>
    </body>
</html>


any ideas?

thanks

Link to comment
Share on other sites

thanks for the reply riwan, but it didnt work.

 

could it be that all the other $_POST varables are available because they come from a $_POST

request while the id is a $_GET in a $_POST form. though i was under the impression that requests in the url are accessible no matter  the method in the form

Link to comment
Share on other sites

well, when you access this from other page it should work

http://portal:8080/events/admin/editEvent.php?id=14

but if you're submitting a form with method post, you shouldn't put ?id= in the action

but instead store the id value in the hidden field so you can retrieve the id value using $_POST["id"]

 

Link to comment
Share on other sites

well, when you access this from other page it should work

http://portal:8080/events/admin/editEvent.php?id=14

but if you're submitting a form with method post, you shouldn't put ?id= in the action

but instead store the id value in the hidden field so you can retrieve the id value using $_POST["id"]

 

i am redirecting from a link in another page. it redirects from this code in a seperate php file


while($row = mysql_fetch_assoc($result)) {
    // Display the row
    $id = $row['id'];
    $caption =  $row['caption'];
    $content = $row['content'];
    $event_image = $row['event_image'];

    /**
     * show each article with edit/delete links
     */
    echo "<div>ID: $id</div>";
    echo "<div>Caption: $caption</div>";
    echo "<div>Content: $content</div>";
    echo "<div>Event Picture: $event_image</div>";
    echo "<div><a href=\"editEvent.php?id=$id\">Edit</a> | <a href=\"deleteEvent.php?id=$id\">Delete</a></div>";
    echo"<br /><hr />";

}


Link to comment
Share on other sites

what I mean is change the way you create your form

        $form->startForm("editEvent.php"); // this would make your form action doesn't contain the id

I'm not sure how you create hidden input using class.form.php as I didn't have it.

it should be output sth like this

<input type="hidden" name="id" value="<?php echo $_GET["id"];?>">

Link to comment
Share on other sites

what I mean is change the way you create your form

        $form->startForm("editEvent.php"); // this would make your form action doesn't contain the id

I'm not sure how you create hidden input using class.form.php as I didn't have it.

it should be output sth like this

<input type="hidden" name="id" value="<?php echo $_GET["id"];?>">

 

thanks..it woked

Link to comment
Share on other sites

Try this in another php file on it's own and send it a ?id=1000 or something in the url:

 

<?php
echo $_GET['id'].'<br />';
echo $id.'<br />';
?>

 

It should only echo once, if you see it twice then register globals is on and you need to disable it with your host.

 

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.