0

so i have a zoom.php where i have a link.

<a href='deleteimage.php?imgid={$row['image_id']}'>Delete</a>

if user click on it it goes to deleteimage.php where i have a form. in form i have field where i store imagid.

<form class="form" action = 'deleteimage.php' method = 'post'>
    <input type='submit' class='button' value='Yes'>
    <input type="hidden" name ="random" class="random" value="<?php echo($_GET['imgid']);?>" />
                <br/><br/>
                <br/>
                <br/>
</form>

now if user click on submit button it run php code. note its still on deleteimage.php page.

if(isset($_SESSION['username']))      /*** user is loged in ***/
{
    if($_SERVER['REQUEST_METHOD'] == 'POST')     //user hit submit button
    {
        $user_id_s = $_SESSION['user_id'];
        $image_id_g  = $_POST['random'];    

if(!$tester = mysql_query("SELECT * FROM image WHERE  image_id = '$image_id_g' AND user_id = '$user_id_s'"))
        {
                $del_image = mysql_query("DELETE FROM image WHERE image_id = '$image_id_g'");
                $del_comment = mysql_query("Delete From comment Where image_id = '$image_id_g'");
        }

here i get a error.

<br /><b>Notice</b>:  Undefined index: imgid in <b>C:\xampp\htdocs\a_upload\deleteimage.php</b> on line <b>51</b><br />

note. line 51 is:

<input type="hidden" name ="random" class="random" value="<?php echo($_GET['imgid']);?>" />

.
.
.
so the problem is that:
The first time deleteimage.php is requested, it's with a GET request that includes imgid in the URL. The second time it's requested, it's with a POST request that doesn't have imgid in the URL. So $_GET['imgid'] is undefined.

do to fix this i was going to
You could keep the query string in the post target, or use the post method to get to the form initially.
but have no idea how to do this. any help will be helpful

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by simplypixie
0

Hello, maybe this will help that u put <?php ?> to delete-link??

<a href='deleteimage.php?imgid=<?php $row['image_id'] ?>'>Delete</a>

Also does $row['image_id'] have value in that zoom.php?

0

<a href='deleteimage.php?imgid=<?php $row['image_id'] ?>'>Delete</a>

already tried it dont work.

$row['image_id']

it does have the right value in zoom.php and deletemage.php

Edited by hwoarang69

0

$imagid cannot be set as you are not echoing it. Change to:

<a href='deleteimage.php?imgid=<?php echo $row['image_id']; ?>'>Delete</a>
0

<a href='deleteimage.php?imgid=<?php echo $row['image_id']; ?>'>Delete</a>

i did change this bu it didnt make it any differece. the value from row['image_id'] does go in deleteimage.php. but the problem i that

so the problem is that:
The first time deleteimage.php is requested, it's with a GET request that includes imgid in the URL. The second time it's requested, it's with a POST request that doesn't have imgid in the URL. So $_GET['imgid'] is undefined.

0

When you view the source code where the original link is, imgid=xx got a value?

If so, when you get to the next page and view source, does your random input field have a value?

If the answer is no to either of these then that is your problem.

Mixing Get and Post doesn't cause errors unless you are using $_GET['imgid'] somewhere else in your second page that you are not displaying and that would come back with it not being definied when you post the data.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.