Trying to redirect from inside an iframe ... that's the code:

<?php
include'file_constants.php';
$imgid = $_GET['id'];
$con = mysql_connect($host, $user, $pass) or die("Can not connect to database: ".mysql_error());
mysql_select_db($db_name) or die("Can not select the database: ".mysql_error());

$sql = mysql_query("SELECT * FROM comments WHERE ImageID =  '$imgid' ORDER BY Date DESC");



while($comment = mysql_fetch_array($sql))
{
    echo "Comment ID -  ",$comment['CommentID'];
     ?><br/><br/><?php ;
   echo $comment['Comment'];
?><p/><p/><br/>
<?php
echo $comment['Date'];?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php
echo $comment['ComUserID'];

?>
                    <form action="deletecomment.php" target="_top" method="post" >
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                    <input type="radio" name="del" /> 
                    <input type="hidden" name="imageid" value="<?=$comment['CommentID']?>" />
                    <input type="submit" style="font-weight: bold;height: 25px; width:130;"  value="Delete Comment" />
                    </form>
<p/><p/>--------------------------------------------------------------------------------------------------------------<p/><?php
}
mysql_close($con);
?>

and thats what im getting(it opens in a separate wndow) :

Notice: Undefined index: id in P:\xampp\htdocs\admincomments.php on line 3

it suppose to redirect to another page which basically is :
`

$echo "deleting";

`

Member Avatar for diafol

Where's the iframe?

Are you trying to redirect the page with the nested iframe? Basically if you click delete in the iframe, you want it to redirect the main page.

iframe is on the different page:

`

<?php



$imgid = $_GET['id'];

include 'ufunction.php';
include 'uthumbfunction.php';
?>
<br/><br/><div class="leftframe">
<div class="frame"><img src="show.php/?id=<?=$imgid?>/%<?=$image['thumb']?>.large.jpg" />
<br/><br/><br/>


<?php
 include "file_constants.php";  //include file with database details such as username\password\database name and table names
 // Connect to server and select databse.
$con = mysql_connect("$host", "$user", "$pass")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
        if ($db_name)
            {
                $sql="SELECT AvrgRate FROM images WHERE id ='$imgid'";                                                                      // select name of logged in user
                $result = mysql_query($sql);
                if ($row = mysql_fetch_assoc($result)) 
                    {
                        $AvrgRate = $row['AvrgRate'] ;                                                                  
                    }
                    else $AvrgRate = 'Not rated yet';
                mysql_close($con);
            }
?>

<h3>
AVERAGE RATE  OF THIS PICTURE IS </h3></p>
<h1><?=$AvrgRate?></h1>
</div>
</div>

<div class="rightframe">
<h2><br/><br/>Comments left :</h2><br />

<div class="iframe"><iframe style="background: rgba(255, 255, 255, 0.5);"src="admincomments.php/?id=<?=$imgid?>"  frameborder="3" width="500" height="550">    

</iframe>
<input type="button" style="background-color:#6BC462; margin:0px 0epx;" value="Close Window" onClick= "javascript:window.close()" />
</div>
</body>
</html>

`

"What goes on in Vegas, stays in Vegas."

What goes on in a IFrame, stays in that iFrame.

I think deletecomment.php is being called and IT is doing a redirect back to admincomments.php but is not passing an id in the url (since you just deleted that comment, there is nothing logical to pass.) That's why the notice.

If you don't want a new window popping open, get rid of the target="_top" in the form action. If you're trying to break out of the iframe and change the url of the containing page, try target="_parent". (I know that worked with FRAMES but I haven't tested this with iFrames.)

That is strange, it should not redirect back to admincomments.php it just has to remove comment at the background and thats all....Can anyone suggest any solution for this please... ?

By background do you mean AJAX? I don't see any hint of Javascript in the code you posted. I'm going by how the form was declared:

<form action="deletecomment.php" target="_top" method="post" >

Member Avatar for diafol

This is the container.php page:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<p>hello</p>
    <iframe src="form.php" width="500" height="500"></iframe>
</body>
</html>

This is the form.php page:

<?php
    if(isset($_POST['loop'])){
        echo "YES"; 
    }

?>
<!-- html dtd etc taken out for clarity -->
<form method="post">
    <input name="loop" />
    <input type="submit" value="submit" />
</form>

When I sublit the form everything stays inside the iframe - as it should. Is this what you're trying to achieve?

..Well I have a page that has an iframe (adminlook.php opens up in a separate window) ..
Heres the code

<body>
<img id="background-img" class="bg" src="adminbackground.jpg" alt="" />  
<?php

$imgid = $_GET['id'];

include 'ufunction.php';
include 'uthumbfunction.php';
?>
<div class="leftframe">
<div class="frame"><img src="show.php/?id=<?=$imgid?>/%<?=$image['thumb']?>.large.jpg" />



<?php
 include "file_constants.php";  
 $con = mysql_connect("$host", "$user", "$pass")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
        if ($db_name)
            {
                $sql="SELECT AvrgRate FROM images WHERE id ='$imgid'";                                                                      // select name of logged in user
                $result = mysql_query($sql);
                if ($row = mysql_fetch_assoc($result)) 
                    {
                        $AvrgRate = $row['AvrgRate'] ;                                                                  
                    }
                    else $AvrgRate = 'Not rated yet';
                mysql_close($con);
            }
?>

<h3>AVERAGE RATE  OF THIS PICTURE IS </h3></p>
<h1><?=$AvrgRate?></h1>
</div>
</div>

<div class="rightframe">

<h2>Comments left by others:</h2>
<div class="iframe"><iframe style="background: rgba(255, 255,255,0.5);
"src="admincomments.php/?id=<?=$imgid?>"  frameborder="3" width="500"height="550">   

</iframe>
<input type="button"  value="Close Window" onClick= "javascript:window.close()" />
</div>
</body>
</html>

iframe content from a different page "admincomments.php" (javascript is there only for closing the whole page)
Heres the code for admincomments.php :

<?php
include'file_constants.php';

$imgid = $_GET['id'];

$con = mysql_connect($host, $user, $pass) or die("Can not connect to database: ".mysql_error());
mysql_select_db($db_name) or die("Can not select the database: ".mysql_error());

$sql = mysql_query("SELECT * FROM comments WHERE ImageID =  '$imgid' ORDER BY Date DESC");



while($comment = mysql_fetch_array($sql))
{
    echo "Comment ID -  ",$comment['CommentID'];
    echo $comment['Comment'];
echo $comment['Date'];
echo "User ID : ";
echo $comment['ComUserID'];

$commentID = $comment['ComUserID'];

?>
        <form action="deletecomment.php" target="_parent" method="post" >
        <input type="radio" name="del" /> 
        <input type="hidden" name="comid" value="<?=$commentID?>" />
        <input type="submit"  value="Delete Comment" />
        </form>
<p></p><p></p>----------------------------------------------------------<p></p><?php
}
mysql_close($con);
?>

This admincomments.php retrieves all comments for the image with this id -->

$imgid = $_GET['id'];

and also it displays a form(button) next to each comment. That button allows to delete this comment. When pressing on that button it supose to redirect to the page called "deletecomment.php"
Heres the code:

<head>
<style>
.bg{position:absolute;width: 20%;height:18%;margin:200px 620px;}
</style>

<script type="text/javascript"> 
function declined()
 { 
    alert("Didn't work....") 
    window.location="allcomments.php";
 } 
</script>
</head>

<body>
<img  class="bg" src="wait.gif" alt="" />    
     <?php

     {
        include "file_constants.php";
        $comdel = $_COOKIE['comdel'];
        $con = mysql_connect("$host","$user","$pass");
            if (!$con)
                {
                      die('Could not connect: ' . mysql_error());
                }
            mysql_select_db("$db_name", $con)or die(mysql_error());
            $query="DELETE FROM comments WHERE CommentID = '$comdel'  ";
            if(mysql_query($query))
                {
                    mysql_close($con);
                    setcookie( $comdel, " ");
                    header( 'Location: allcomments.php' );
                }
            else
                {
                    mysql_close($con);
                    setcookie( $comdel, " ");
                    ?><script>declined();</script><?php

                }
    }
?>
</body>

Its basically supose to delete the comment and redirect to different page ....
But thats what im getting in addres bar :

http://localhost/admincomments.php/deletecomment.php

and thats the error:

Notice: Undefined index: id in P:\xampp\htdocs\admincomments.php on line 3

Thnks

Never mind .. I removed delete button.. No button - no problem.. I have another menu option that allows admin to delete any comment. This one was just like a bonus function...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.