douzi7219 2016-05-06 11:25
浏览 24

PHP变量没有通过GET传递给另一个页面

I have this while-loop code for returning data from database

if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_array($result)) {
        (some not important lines...)
        echo "<div><a href='remove.php?id=<?php echo ".$row['id'].";?>'>remove record</a></div>";

and I want to pass id variable by GET to my remove.php

<?php
    include '../db.php';
    $id = $_GET['id'];
    $con = mysqli_connect($host, $user, $pass, $db);
    mysqli_query($con, 'DELETE FROM zapisy WHERE id='$id';')
    mysqli_close($con);
?>

but everytime I click on my link it redirects to

remove.php?id=<?php%20echo%2042;?> // <?php echo 42;?> without all that mess, id is good

leaving that php tags, that I think should not be here, and not passing my variable to another page - first problem; second - php returns

Parse error: syntax error, unexpected T_VARIABLE in .../admin-panel/remove.php on line 5

which tells me something is wrong with the mysql spelling nearby variable, but I was looking for answer and nothing. I changed ' ' to " " and opposite, and nothing. Or is it because variable is not getting value passed and its empty?

I would be very thankful if someone could help me or point me the right path, because I'm stuck at this point and I am just beginning with coding.

  • 写回答

5条回答 默认 最新

  • dongping4461 2016-05-06 11:27
    关注

    Change your code to :

    if(mysqli_num_rows($result) > 0)
    {
        {
        while($row = mysqli_fetch_array($result)){
            (some not important lines...)
    ?>
            <div><a href='remove.php?id=<?php echo $row['id'];?>'>remove record</a></div>
    <?php }
    }
    

    OR

    if(mysqli_num_rows($result) > 0)
        {
            {
            while($row = mysqli_fetch_array($result)){
                (some not important lines...)
    echo "<div><a href='remove.php?id=".$row['id']."'>remove record</a></div>"
    
    评论

报告相同问题?