drll42469 2013-04-18 11:29
浏览 55
已采纳

php - 通过链接将变量发送到下一页

I need help.

How can I call the variable(within the url) after a successful search result in my index.php to the next page view.php so that I can view the complete data of the variable?

heres my code

"index.php"

<form method="post" action="index.php?go" id="searchform">
<input type="text" name="name" size = "50">
<br/>
<input type="submit" name="submit" value="SEARCH">
<button type="reset" value="Reset">RESET</button>
</form>


<?php

    $db=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error()); 
    $mydb=mysql_select_db("emp_dbA");

    if(isset($_POST['submit'])){
    if(isset($_GET['go'])){
    if(preg_match("/[A-Z | a-z]+/", $_POST['name'])){
    $name=$_POST['name'];
    $letter=$_GET['by'];

    $sql="SELECT emp_ID, fname, lname,mname FROM emp_tbl WHERE fname LIKE '%" . $name . "%' OR lname LIKE '%" . $name ."%' OR mname LIKE '%" .$name . "%'";
    $result=mysql_query($sql);  
    $numrows=mysql_num_rows($result);

    echo "<p>" .$numrows . " results found for " . stripslashes($name) . "</p>"; 

    while($row=mysql_fetch_array($result)){

    $fname =$row['fname'];
    $mname =$row['mname'];
    $lname=$row['lname'];
    $ID=$row['emp_ID'];

        echo "<ul>
"; 
        echo "<li>" . "<a href=\"view.php?id=$fname\">"  .$fname . " " . $mname. " " . $lname . "</a></li>
";
        echo  "</ul>";
                                            }
                                                    }
        else{
        echo "<p>Please enter a search query</p>";
            }


                            }
    }

?>

  • 写回答

5条回答 默认 最新

  • doucuo9126 2013-04-18 11:39
    关注

    You get the URL parameters with the $_GET environment variable, while the field you did put inside the form (given that you chose post as the form method) will be read like $_POST["name"].

    As a little piece of advice, try to resort to the GET method as few times as possible. Parameters received with the GET method are seen in the URL, while parameters received from the POST method aren't.

    And, of course, sanitize all your GET/POST data before actually using it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据