0

so i have a page where where is a link

<a href=\"editimage.php?img=".$image_id."\">asdf</a>

an another page i have to get the image_id that i am passing

$image_id_g = isset($_GET['img']) ? $_GET['img'] : 0;
echo"$image_id_g";

but the problem is that it prints 0 here. but i wan tto print image_id

3
Contributors
15
Replies
16
Views
5 Years
Discussion Span
Last Post by hwoarang69
Featured Replies
  • 1
    diafol 3,669   5 Years Ago

    If your url actually shows something like `editimage.php?img=3`, then it should work: $image_id_g = (isset($_GET['img'])) ? intval($_GET['img']) : 0; echo $image_id_g; Read More

  • 1
    diafol 3,669   5 Years Ago

    Whoaa - I ain't gonna wade through all that code just for a quite $_GET variable! Did you try my fix? Read More

  • 1
    diafol 3,669   5 Years Ago

    Why does it say image_id? It should be a number? Read More

  • That code should work correctly. Are you sure that your server allows you to use GET variables? Create a page named test.php with this code and post what is displayed when you try going to the page test.php?img=1 <?php echo('<pre>'); print_r($_GET); echo('</pre>'); ?> Read More

  • Do you know what version of PHP you are using? The GET variables are not working on your server. Read More

1

If your url actually shows something like editimage.php?img=3, then it should work:

$image_id_g = (isset($_GET['img'])) ? intval($_GET['img']) : 0;
echo $image_id_g;

Edited by diafol

0

that so wierd i get in url

editimage.php?img=3,

ill just post all my code. send image_id from zoom.php and recsiving it in editimage.php
zoom.php

<?php
include("include/header.php");

//grab submitted data
if($_SERVER['REQUEST_METHOD'] == 'POST') //if user add comment
{
    if(empty($_POST['comment']))
    {
    }
    else
    {
        $count = 0;
        $comment_p = $_POST['comment'];
        $user_id_s = $_SESSION['user_id'];      
        $image_id_g = isset($_GET['img']) ? $_GET['img'] : 0;

        //success
        $comment = mysql_query("INSERT INTO comment VALUES(NULL,'$user_id_s','$image_id_g','$comment_p')");

        //count comments and update comments
        $queryget = mysql_query("SELECT comment FROM comment WHERE image_id = $image_id_g");
        while($row2 = mysql_fetch_assoc($queryget))
        {
            $count++;
        }
        $result2 = mysql_query("UPDATE image SET image_comment = '$count'  WHERE image_id = '$image_id_g'");    
    }
}
?>


<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
    <link rel='stylesheet' type='text/css' href='css/top_menu.css' />
    <link rel='stylesheet' type='text/css' href='css/all_css.css' />
</head>

<body>
                <?php
                /*
                $visitors = 0;
                $handle = opendir(session_save_path());
                while(($file = readdir($handle)) != FALSE)
                {
                    if($file != "."&&$file !="..")
                    {
                        if( preg_match("^sess",$file))
                        $visitors++;
                    }
                }
                echo "there are $visitors online";
*/
                    $image_id = $_GET['img'];
                    $user_name_s = $_SESSION['username'];
                    //$img = intval($_GET['img']);

                    //get image from database
                    $queryget = mysql_query("SELECT image FROM image WHERE image_id = $image_id");
                    $row = mysql_fetch_assoc($queryget);    
                    $image_db = $row['image'];
                    $src = "data:image/gif;base64," . $image_db;

                    //get image name from database
                    $queryget = mysql_query("SELECT image_short_name FROM image WHERE image_id = '$image_id'");
                    $row = mysql_fetch_assoc($queryget);    
                    $image_short_name_db = $row['image_short_name'];

                    //get image size from database
                    $queryget = mysql_query("SELECT image_des FROM image WHERE image_id = '$image_id'");
                    $row = mysql_fetch_assoc($queryget);    
                    $image_des_db = $row['image_des'];


                    //get image size from database
                    $queryget = mysql_query("SELECT image_size FROM image WHERE image_id = '$image_id'");
                    $row = mysql_fetch_assoc($queryget);    
                    $image_size_db = $row['image_size'];

                    //get image size from database
                    $queryget = mysql_query("SELECT image_resolution FROM image WHERE image_id = '$image_id'");
                    $row = mysql_fetch_assoc($queryget);    
                    $image_resolution_db = $row['image_resolution'];

                    //get image views from database
                    $queryget = mysql_query("SELECT image_view FROM image WHERE image_id = '$image_id'");
                    $row = mysql_fetch_assoc($queryget);    
                    $image_view_db = $row['image_view'];

                    //get image size from database
                    $queryget = mysql_query("SELECT image_comment FROM image WHERE image_id = '$image_id'");
                    $row = mysql_fetch_assoc($queryget);    
                    $image_comment_db = $row['image_comment'];

                    //get all comments
                    $result2 = mysql_query("SELECT * FROM comment WHERE image_id = '$image_id' ORDER BY image_id DESC");



                    echo"
                        <div id ='bg4'>
                            <div id='context4'>

                                <div class='image_nu'>
                                    <br/><img src=\"$src\"  class='image' /><br/><br/>
                                        <b><font color='#1d98d6'> " . $image_short_name_db . "</font></b><br/>
                                        <b><font color='#1d98d6'>By: " . $user_name_s . "</font></b><hr/>
                                </div>

                                <div id='image_des'>
                                     " . $image_des_db . "<br/><br/>
                                </div>

                                <div id='image_bottom'>

                                    <form class='form' action='zoom.php?img=$image_id' method='post'>
                                        <b> " . $user_name_s . " - Add a Comment:</b><br/>
                                        <pre> <textarea class='textarea' name='comment'></textarea></pre>
                                        <pre> <input type='submit' class='button' name='submit' value='Add comment' /></pre>
                                     </form>
                                </div>

                                <div id='image_right'>
                                    <div id = 'nav2'>
                                        <ul>
                                            <li><a href=\"editimage.php?img=".$image_id."\">Edit</a></li> 
                                            <li><a href='#'>Delete</a></li>
                                        </ul>
                                    </div>
                                </div>

                                <div id='image_right2'>
                                    <div class='form'>
                                        <b>Statistics:</b><br/>
                                        <b>View: " . $image_view_db . "</b><br/>
                                        <b>Comment: " . $image_comment_db . "</b><br/><hr/>
                                        Image information:<br/>
                                        <b>Size: " . $image_size_db . "</b><br/>
                                        <b>Resolution: " . $image_resolution_db . "</b><br/>
                                    </div>
                                </div>       

                                <div id='image_comment' class='form'> ";
                                        while($row2 = mysql_fetch_assoc($result2))
                                        {
                                            $comment_db = $row2['comment'];  //get comment from comment table
                                            $user_id_db = $row2['user_id'];  //get user id from comment table

                                            //get user name from user table
                                            $queryget = mysql_query("SELECT username FROM user WHERE user_id = '$user_id_db'");
                                            $row = mysql_fetch_assoc($queryget);    
                                            $user_name_db = $row['username'];

                                            echo"<font color='#DBDBDB'>$user_name_db</font><br/>";
                                            echo"$comment_db <br/><br/><hr/><hr/>";
                                        }

                            echo"</div>
                                <br/>
                            </div>
                        </div>
                    ";
                ?>
</body>


<?php
    incl

ude("include/footer.php");
?>

editimage.php

<?php
include("include/header.php");

//check, if user is loged in or not
if(isset($_SESSION['username']))      /*** user is loged in ***/
{
    $edit_img_error = "";
    if($_SERVER['REQUEST_METHOD'] == 'POST')     //user hit submit button
    {
        if(empty($_POST['image_short_name']) || empty($_POST['image_des']))
        {
            $edit_img_error .= "Missing field! Please fill in  all field!";
        }
        else
        {
            $user_id_s = $_SESSION['user_id'];
            $image_id_g = isset($_GET['img']) ? $_GET['img'] : 0;

            $image_short_name_p =  $_POST['image_short_name'];
            $image_des_p       =  $_POST['image_des'];

            echo"$image_id_g";
            $querychange_n = mysql_query("UPDATE image SET image_short_name = '$image_short_name_p'  WHERE image_id = '$image_id_g'");
            $querychange_d = mysql_query("UPDATE image SET image_des        = '$image_des_p'         WHERE image_id = '$image_id_g'");

            header('Location: gallery.php');
        }       
    }
}
else
{
    header('Location: error.php');      
}
 $_SESSION['edit_img_error'] = $edit_img_error;
?>



<head>
<title>Untitled Document</title>
            <link rel='stylesheet' type='text/css' href='css/top_menu.css' />
            <link rel='stylesheet' type='text/css' href='css/all_css.css' />
</head>

<body>
                <div id ='bg'>
                <div id='context'>
                    <div id="edit_form">
                        <form class="form" action = 'editimage.php' method = 'post'>
                        <pre><h1> Edit Image</h1><hr/></pre>
                              <?php
                                //print errors
                                if(array_key_exists('edit_img_error', $_SESSION) && !empty($_SESSION['edit_img_error']))
                                {
                                    $edit_error_r = $_SESSION['edit_img_error'];
                                    echo "<span style='background-color:#D00000;'> $edit_error_r </span>";
                                    unset($_SESSION['edit_error']);
                                }
                                ?>
                               <pre> Image Name:  <input class = "field" type="text" size="20" name="image_short_name" /></pre>
                                <pre> Description:</pre>
                                <pre> <textarea class="textarea" name="image_des" maxlength='200' > </textarea></pre>
                                <div id = "test0"></div>
                                <pre>  <input type='submit' class='button' value='save'></pre>
                        </form>
                    </div>
                </div>
            </div>   
</body>


<?php
include("include/footer.php");
?>
1

Whoaa - I ain't gonna wade through all that code just for a quite $_GET variable!
Did you try my fix?

0

yes i tried but failed. it just prints 0 for image_id.
but on url it does say image_id

1

That code should work correctly. Are you sure that your server allows you to use GET variables? Create a page named test.php with this code and post what is displayed when you try going to the page test.php?img=1

<?php
    echo('<pre>');
    print_r($_GET);
    echo('</pre>');
?>
1

Do you know what version of PHP you are using? The GET variables are not working on your server.

0

ah i see the problem but dont know how to fix it.
so when i put print_r($_GET) in my body it works fine. but when urser hit sumbit button it doesnt go in top php code.

<?php
include("include/header.php");

//check, if user is loged in or not
if(isset($_SESSION['username']))      /*** user is loged in ***/
{
    $edit_img_error = "";
    if($_SERVER['REQUEST_METHOD'] == 'POST')     //user hit submit button
    {
        if(empty($_POST['image_short_name']) || empty($_POST['image_des']))
        {
            $edit_img_error .= "Missing field! Please fill in  all field!";
        }
        else
        {
            $user_id_s = $_SESSION['user_id'];
            $image_id_g = isset($_GET['img']) ? $_GET['img'] : 0;

print_r($_GET);

//dont work hereherhehre

            $image_short_name_p =  $_POST['image_short_name'];
            $image_des_p       =  $_POST['image_des'];




            $querychange_n = mysql_query("UPDATE image SET image_short_name = '$image_short_name_p'  WHERE image_id = '$image_id_g'");
            $querychange_d = mysql_query("UPDATE image SET image_des        = '$image_des_p'         WHERE image_id = '$image_id_g'");

            //header('Location: gallery.php');
        }       
    }
}
else
{
    header('Location: error.php');      
}
 $_SESSION['edit_img_error'] = $edit_img_error;
?>



<head>
<title>Untitled Document</title>
            <link rel='stylesheet' type='text/css' href='css/top_menu.css' />
            <link rel='stylesheet' type='text/css' href='css/all_css.css' />
</head>

<body>
                <div id ='bg'>
                <div id='context'>
                    <div id="edit_form">
                        <form class="form" action = 'editimage.php' method = 'post'>
                        <pre><h1> Edit Image</h1><hr/></pre>
                              <?php
                                //print errors
                                if(array_key_exists('edit_img_error', $_SESSION) && !empty($_SESSION['edit_img_error']))
                                {
                                    $edit_error_r = $_SESSION['edit_img_error'];
                                    echo "<span style='background-color:#D00000;'> $edit_error_r </span>";
                                    unset($_SESSION['edit_error']);
                                }
                                ?>

                               <pre> Image Name:  <input class = "field" type="text" size="20" name="image_short_name" /></pre>
                                <pre> Description:</pre>
                                <pre> <textarea class="textarea" name="image_des" maxlength='200' > </textarea></pre>
                                <div id = "test0"></div>
                                <pre>  <input type='submit' class='button' value='save'></pre>
                        </form>
                    </div>
                </div>
            </div>   
</body>


<?php
include("include/footer.php");
?>
1

Coz you're using 'post' from the form.

$image_id_g = isset($_POST['img']) ? $_POST['img'] : 0;

But that name ('img') does not seem to exist in the form.

I can't work out what you're trying to do with the code above. You seem to want to save with the form, so the code line above is probably not what you want. This $_GET['img'] should be taken fromt he url, which in turn should be taken from a link on another page?

I'd suggest that you place this number into a hidden form field and then use that when you come to save.

0

$image_id_g = isset($_POST['img']) ? $_POST['img'] : 0; ?

but iam using

$image_id_g = isset($_GET['img']) ? $_GET['img'] : 0;

i think i know how can i fix this problem.
i can make a hidden field.
this prints

 Array(    [img] => 116). is there a way to only print "116" here??????



 <input type='field' name ='random' class='random' value='<?php print_r($_GET);?>'>

than i can use

$image_id_g = $_POST['random'];

this works fine but it i dont want the

"Array([img]=>)" part
1

This?

<input type="hidden" name ="random" class="random" value="<?php echo($_GET['img']);?>" />
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.