简体   繁体   中英

passing variable from a href to pop up box through php

after i click on this a href, it ll pop out a form and i trying to pass a variable to the pop up form. This is in a while loop.

while($row = mysql_fetch_array($result))                                    
{
$id=$row['file_id'];
echo '<span class=right><a href="#edit_form?id='.$id.'">[edit]</a> 
}

This is the pop up form code

<a href="#x" class="overlay" id="edit_form"></a>
        <?php
            $con=mysql_connect("localhost","root","");
            mysql_select_db("isiti");
            if (mysqli_connect_errno($con))
                {
                    echo "Failed to connect to MySQL: " . mysqli_connect_error();
                }
            if (isset($_GET["id"])) 
            {                           
                $id =$_GET["id"];
            }
            $result = mysql_query("SELECT * FROM publication where file_id='$id'");
            $row1 = mysql_fetch_array($result);
            $title=$row1['title'];
            $author=$row1['author'];
            $year=$row1['year'];
            $abstract=$row1['abstract'];

                        if(!empty($_SESSION['username']))
                        {
                        echo'<div class="popup">';
                             echo'<form method="POST" action="public_edit.php" enctype="multipart/form-data">';
                                        echo'<div>';
                                            echo'<label for="citation">Title</label>';
                                            echo'<input style="width:100%;" type="text" name="title" id="title" value="'.$title.'">';
                                        echo'</div>';
                                        echo'<div>';
                                            echo'<label for="citation">Author</label>';
                                            echo'<input style="width:100%;" type="text" name="author" id="author" value="'.$author.'">';
                                        echo'</div>';
                                        echo'<div>';
                                            echo'<label for="citation">Year</label>';
                                            echo'<input style="width:100%;" type="year" name="year" id="year" value="'.$year.'">';
                                        echo'</div>';
                                        echo'<div>';
                                            echo'<label for="abstract">Abstract</label>';
                                           echo'<textarea name="abstract" id="abstract" size="5000">'.$abstract.'</textarea>';
                                        echo'</div>';
                                        echo'<p>Rechoose your file here</p>';
                                        echo'<input type="hidden" name="MAX_FILE_SIZE" value="2000000">';
                                        echo'<input name="userfile" type="file" id="userfile">&nbsp;';
                                        echo'<br/> ';
                                        echo'<input name="submit" type="submit" value="Upload" style="width: 150px">';
                                echo'<a class="close" href="#close"></a>';
                                echo'</form>';
                        echo'</div>';
                        }

The problem i faced is that it do not pass the right id. no matter what link i click it show the data from the first id.

Thanks for helping me .

You need to pass the id as get parameter when calling that pop up. Replace with this the echo statement in first code

echo '<span class=right><a href="#edit_form?id= ' .$id .'">[edit]</a>'; 

$_GET works well for data sent by a query string. In this case, you are sending the data as the id of href tag. so try attaching id to your query string.

 echo '<span class=right><a href="#edit_form?id='.$id.'">[edit]</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM