Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP存储单击的链接数据并将其传输到新页面_Php_Html_Mysql - Fatal编程技术网

使用PHP存储单击的链接数据并将其传输到新页面

使用PHP存储单击的链接数据并将其传输到新页面,php,html,mysql,Php,Html,Mysql,我正在创建一个web应用程序,允许学生通过HTML表单注册(完成此部分),并将其数据存储在DB中(完成)。我正在使用PHP/MYSQL来写这篇文章 我的想法是,我有一个'后端'将允许管理员搜索一个学生的第一,最后,或全名(这已完成),并显示在下一页的学生名单。(也已完成)。学生名单将是个人超链接 我的页面布局是: backendhome.php <?php $query = $_POST['query']; //gets value sent over from search

我正在创建一个web应用程序,允许学生通过HTML表单注册(完成此部分),并将其数据存储在DB中(完成)。我正在使用PHP/MYSQL来写这篇文章

我的想法是,我有一个'后端'将允许管理员搜索一个学生的第一,最后,或全名(这已完成),并显示在下一页的学生名单。(也已完成)。学生名单将是个人超链接

我的页面布局是:

backendhome.php

 <?php
    $query = $_POST['query']; //gets value sent over from search 
     $query = htmlspecialchars($query); 
        // changes characters used in html to their equivalents, for example: < to &gt;

        $query = mysql_real_escape_string($query);
        // makes sure nobody uses SQL injection

        $raw_results = mysql_query("SELECT * FROM students
            WHERE (`firstName` LIKE '%".$query."%') OR (`lastName` LIKE '%".$query."%')") or die(mysql_error());

  if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following

            while($results = mysql_fetch_array($raw_results)){
            // $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
                echo "<a href='studentData.php'>".$results['firstName']." ".$results['lastName']."</a></br>";
                // posts results gotten from database you can also show id ($results['id'])
            }

        }
        else{ // if there is no matching rows do following
            echo "No results";
        }
  ?>
  • 有搜索栏和搜索按钮
search.php

  • 单击搜索时,将执行此页面,该页面将获取搜索的项目并在数据库中找到该项目

  • 吐出所有名/姓/全名学生的数据(可能是多个学生)-这些是超链接

我在search.php上使用的代码段搜索方法

 <?php
    $query = $_POST['query']; //gets value sent over from search 
     $query = htmlspecialchars($query); 
        // changes characters used in html to their equivalents, for example: < to &gt;

        $query = mysql_real_escape_string($query);
        // makes sure nobody uses SQL injection

        $raw_results = mysql_query("SELECT * FROM students
            WHERE (`firstName` LIKE '%".$query."%') OR (`lastName` LIKE '%".$query."%')") or die(mysql_error());

  if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following

            while($results = mysql_fetch_array($raw_results)){
            // $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
                echo "<a href='studentData.php'>".$results['firstName']." ".$results['lastName']."</a></br>";
                // posts results gotten from database you can also show id ($results['id'])
            }

        }
        else{ // if there is no matching rows do following
            echo "No results";
        }
  ?>

您可以按如下所述传递您的学生id,并在studentData.php页面中获取该
id
,然后检索学生信息并显示它

echo "<a href='studentData.php?id=".$results['id']."'>".$results['firstName']." ".$results['lastName']."</a></br>";
                         .......^
echo“
”; .......^
非常感谢您!这起作用了。我提取了url,然后使用子字符串来获取我的id。现在我可以继续这个项目了!