【问题标题】:PHP url parameter passing to other php page [closed]PHP url参数传递到其他php页面[关闭]
【发布时间】:2011-10-12 07:23:36
【问题描述】:

我无法通过 url 参数将值传递到其他页面。我想通过单击 REJECT 按钮拒绝基于所选 bookingID 的预订。但是bookingID的值没有传到其他页面,url像这样http://localhost/tablesortapprovebook/approve_booking.php?bookingID=

这是我的编码段:

index.php

<head>
<script src="jquery-latest.js" type="text/javascript"></script>
<script src="jquery.tablesorter.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$("#myTable").tablesorter({widgets: ['zebra']});
});

$(document).ready(function() 
{ 
    $("#myTable").tablesorter(); 
} 
);

$(document).ready(function() 
{ 
    $("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} ); 
} 
);
</script>
<link href="style.css" rel="stylesheet" type="text/css">
<link href="stylelogin.css" rel="stylesheet" type="text/css">
</head>
<body>

<?php

include("dbconfig.php");

$query = "SELECT customer.companyName, customer.contactName, eventinfo.eventTitle,boothAlias,date, testbook.bstatus, testbook.username, bookingID  from eventinfo, testbook, customer where testbook.username=customer.username AND testbook.eventID=eventinfo.eventID";

$o = '<table id="myTable" class="tablesorter" width="930px"><thead><tr><th>Company Name</th><th>Contact Name</th><th>Event</th><th>Booth</th><th>Date</th><th>Status</th></tr></thead><tbody>';



$result = mysql_query($query);
        while($row=mysql_fetch_array($result))
        {
        $boothAlias=stripslashes($row["boothAlias"]);
        $eventTitle=stripslashes($row["eventTitle"]);
        $date=stripslashes($row["date"]);
        $bstatus=stripslashes($row["bstatus"]);
        $companyName=stripslashes($row["companyName"]);
        $contactName=stripslashes($row["contactName"]);
        $bookingID=stripslashes($row["bookingID"]);


if($bstatus==0){
    $status="Pending";
}else if($bstatus==1){
    $status="Successful";
}else{
    $status="Reject";
}


$o .= '<tr><td width="120px">'.$companyName.'</td><td width="120px">'.$contactName.'</td><td width="180px">'.$eventTitle.
'</td><td width="70px">'.$boothAlias.'</td><td width="170px">'.$date.'</td><td width="70">'.$status.'</td><td>'.$bookingID.'
</td><td width="100"><input type="hidden" name="bookingID" value="<?php echo $bookingID; ?>" ><a href="approve_booking.php?bookingID=".$bookingID.
" name="REJECT" id="REJECT"><input width="100px" name="REJECT" type="submit" id="REJECT" value="Reject"></a></td></tr>';
}

$o .= '</tbody></table>';

echo $o;
?>

</body>

approve_booking.php

<?php

mysql_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db("eventdb") or die (mysql_error());

$booking=$_GET['bookingID'];
echo $booking;

if(isset($_POST['APPROVED']))
    {

        $query2 = "UPDATE testbook SET bstatus ='0' WHERE bookingID='$booking'";
            $result2 = @mysql_query($query2);
    }


if (isset($_POST['REJECT']))
    {
        $query3 = "UPDATE testbook SET bstatus ='2' WHERE bookingID='$booking'";
            $result3 = @mysql_query($query3);

    }



?>

【问题讨论】:

  • 1) 注意 SQL 注入 2) 删除错误抑制器,尤其是在开发环境中 3) 如何传递查询字符串?我只看到一个损坏/不完整的表格。如果它使用 GET 方法,那么 2 个 POST 是在哪里生成的? 4)是的,你的问题是什么?
  • 您是否对 GET 和 POST 请求感到困惑? GET 变量将通过 URL 传递,并且可以使用 $_GET[''] 获取,而 POST 通过 html 表单发送。您是否也知道 $_SESSION?

标签: php url parameters


【解决方案1】:

我真的不知道您的问题是什么,但请尝试使用 $_REQUEST['....'] 而不是 $_GET['...']。

顺便说一句,你有一个 SQL 注入漏洞:

$booking=$_GET['bookingID'];

将其替换为:

$booking=mysql_escape_string($_GET['bookingID']);

【讨论】:

    【解决方案2】:

    这里有很多无效的语言用法。您的具体问题:

     '</td><td width="100"><input type="hidden" name="bookingID"
       value="<?php echo $bookingID; ?>" >
     <a href="approve_booking.php?bookingID=".$bookingID." name="REJECT"'
    

    您在'single quote' 上下文中,因此".$bookingID." 将不起作用。事实上,不正确的双引号只是终止了这里的 HTML 属性。

    上面的&lt;?php echo... 在字符串中也不起作用(无论是单引号还是双引号)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-29
      • 2017-11-09
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 2013-07-17
      • 1970-01-01
      • 2018-09-05
      相关资源
      最近更新 更多