du548397507 2016-04-21 16:36
浏览 50

PHP没有将变量传递给其他页面

I'm trying to pass the variable from one page to another. However, when I try to get the variable using php it just passes it as a string to the other page.

'<a href="selected.php?varname=<?php echo $row[title]; ?>">' . $row['title'] . '</a>'

This is a cell in a table and is a link that when clicked should go the other page with the title. However, instead I get this.

array (size=1) 'varname' => string '' (length=26)

        <?php
        $mysqli = mysqli_connect('localhost','scott','tiger','courses');
        if(mysqli_connect_errno($mysqli)) {
            echo 'Failed to connect to MySQL: ' . mysqli_connect_error();
        }

        class Courses
        {
            public $title;
            public $id;
            public $award;
        }


        $res = mysqli_query($mysqli, "SELECT title,id,award FROM course LIMIT 10");
        echo "<table align='center' style='margin: 0px auto;'>";
        while($row = $res->fetch_assoc()) {
            $courses = new Courses;
            $courses->title = $row['title'];
            $courses->id = $row['id'];
            $courses->award = $row['award'];
            $varname = $row['title'];
            echo "<tr><td style='padding-right:25px'>" . '<a href="selected.php?varname=<?php echo $row[title]; ?>">' . $row['title'] . '</a>' . "</td><td style='padding-right:25px'>" . $row['id'] . "</td><td style='padding-right:25px'>" . $row['award'] . "</td></tr>";
        }
    ?>

That is the rest of the php code.

            <?php
            $var_value = $_GET['varname'];

            echo serialize($var_value);

            var_dump($_GET);
            exit;

This is where I try to get it in the other page

  • 写回答

1条回答 默认 最新

  • doujiku1028 2016-04-21 16:37
    关注

    Rewrite the code as below

    "<a href='selected.php?varname=$row[title]'>$row['title']</a>"
    

    As said in the docs

    The most important feature of double-quoted strings is the fact that variable names will be expanded

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效