dpik71879 2013-03-30 08:06
浏览 18

在php中的URL中传递值[关闭]

I know that one can pass a value in a url when the submit button is clicked like:
action= assignastemp.php?value1=a and then retrieve it in assignastemp file using $query=$_GET['value1']; so that $query would take the value a.

Now, check out the following:

I have this line of code in my assignastemp file so that i can retrieve the professor id in the variable $query: $query=$_POST['searchprofid'];

In the action field of assignastemp i have put: action= 'sendmail.php?prof_id=$query' since i want that this same professor id be passed to my next form sendmail.php so that i can also display and use it in sendmail.php. But it is not passing the value. Please tell me the correct syntax.

Here's my search.php file (it works fine and gives me proper results, but does not pass prof_id to assignastemp.php):

<?php
include('connectionfile.php');

    $query=$_POST['searchprofid'];
    $query1 = $_POST['searchprofname']; 
    $query2=$_POST['searchprofdesignation'];
    $query3=$_POST['searchprofexperience'];
    $query4=$_POST['searchprofemail'];
    $query5=$_POST['searchprofcolg'];
    $query6=$_POST['searchprofsubject'];


    echo "<br><p>";

        $raw_results = mysql_query("SELECT * FROM professor  WHERE (`prof_id` LIKE '%".$query."%') AND (`prof_name` LIKE '%".$query1."%')  AND (`designation` LIKE '%".$query2."%')  AND (`experience` LIKE '%".$query3."%')  AND (`prof_email_id` LIKE '%".$query4."%')  AND (`college_name` LIKE '%".$query5."%') AND (`subject_name` LIKE '%".$query6."%') ") OR die(mysql_error());

    $number= mysql_num_rows($raw_results);
    echo "<br>No. of results returned: ";
    echo "$number";

if($number > 0)
{

     echo ( "<form id='assign' action= 'assignastemp.php?prof_id=$query' method='post'> <table border='1' cellpadding='8' cellspacing= '6' bgcolor= 'white' bordercolor='158bee' align='center' >" ) ; 
            while($results = mysql_fetch_array($raw_results))
    {           
                echo ("<tr><td><p>".$results['prof_id']."</td><td>".$results['prof_name']."</td><td>".$results['designation']."</td><td>".$results['experience']."</td><td>".$results['prof_email_id']."</td><td>".$results['college_name']."</td><td>".$results['subject_name']."</td> ");

     echo(" <td><center><input type= 'submit' name='assign' value= 'Assign' /> </td>"); 

    /* echo(" <td><center><input type= 'hidden' name='prof_id' value='prof_id' /> </td>"); */

    echo("</p></tr>");
                }
    echo("</table></form>"); 
}

        else
        { 
            echo "<br> No matches found.";
        }

mysql_close($id_link);


?>

Here's **assignastemp.php**:<?php
include('connectionfile.php');

$prof_id= $_POST['prof_id'];  

 echo("</p> Professor ID: $prof_id"); 
mysql_close($id_link);


?>
  • 写回答

2条回答 默认 最新

  • dongya9346 2013-03-30 08:08
    关注

    Attaching parameters at the end of your url like: ?prof_id=$query sends them through GET, and thus you can only access the value through $_GET['prof_id'] or $_REQUEST['prof_id']; There's a difference between POST And GET, as shown in this question.

    评论

报告相同问题?

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上