在其他php文件中使用URL变量
我正在使用传递到另一个php文件的URL值。但是,每次我尝试将name变量的值与下面的普通变量结合使用时,PHP都不会读取它在其他php文件中使用URL变量,php,Php,我正在使用传递到另一个php文件的URL值。但是,每次我尝试将name变量的值与下面的普通变量结合使用时,PHP都不会读取它 global $counterforlist; $counterforlist= 0; echo "<form method=\"POST\" action=\" ".htmlspecialchars($_SERVER['PHP_SELF'])."\" > "; echo "<table>"; echo "<tr><td>
global $counterforlist;
$counterforlist= 0;
echo "<form method=\"POST\" action=\" ".htmlspecialchars($_SERVER['PHP_SELF'])."\" > ";
echo "<table>";
echo "<tr><td>ID:</td><td>Company Name</td><td>Date for Service</td><td>Edit</td><td>Delete</td></tr>";
while ($row = mysql_fetch_array($result)){
$counterforlist = $counterforlist +1;
echo "<td><input type= 'text' name = 'jobrequestnumber$counterforlist' value =".$row['jobrequestnumber']."></td>" ;
echo "<td><input type= 'text' name = 'requestingcompany$counterforlist' value =".$row['requestingcompany']."></td>" ;
echo "<td><input type= 'text' name = 'dateforService$counterforlist' value =".$row['dateforService']."></td>" ;
echo "<td><a href=\"update_request.php?jobrequestnumber{$counterforlist}={$row['jobrequestnumber']}&requestingcompany{$counterforlist}={$row['requestingcompany']}&dateforService{$counterforlist}={$row['dateforService']}&{$counterforlist}={$counterforlist}\">Update</a></td>";
echo "<td><a href='delete.php?jobrequestnumber=".$row['jobrequestnumber']."'>Delete</a></td>"; //too
echo "</tr>";
<?php include('update_request.php');?>
global$counterforlist;
$counterforlist=0;
回声“;
回声“;
echo“ID:ServiceEditDelete的公司名称日期”;
while($row=mysql\u fetch\u数组($result)){
$counterforlist=$counterforlist+1;
回声“;
回声“;
回声“;
回声“;
回声“;//也是
回声“;
这是另一个调用这些值的php文件 在更新请求中:
<?php
global $counterforlist;
$jobrequestnumber=$_GET["jobrequestnumber"."$counterforlist"];
$requestingcompany=$_GET["requestingcompany"."$counterforlist"];
$dateforService=$_GET["dateforService"."$counterforlist"];
$required_array=array($jobrequestnumber,$requestingcompany,$dateforService);
$errors = array();
$errors = array_merge($errors, check_required_fields($required_array, $_POST));
if (empty($errors)){
// Database submission only proceeds if there were NO errors.
$query = "UPDATE jobrequest SET
requestingcompany = '{$requestingcompany}',
dateforService = {$dateforService}
WHERE jobrequestnumber ={$jobrequestnumber}";
echo $jobrequestnumber;
$result = mysql_query($query);
是,并且?您的另一个PHP文件没有定义$counterforlist
,因此
$jobrequestnumber=$_GET["jobrequestnumber"."$counterforlist"];
被视为
$jobrequestnumber=$_GET["jobrequestnumber"];
由于您正在发送jobrequestnumber1
、jobrequestnumber2
等,因此简单的jobrequestnumber
将不存在
PHP中的global
不会使一个变量在多个不同的脚本中持久化。除非在函数()中使用该声明,否则无论如何都不会太多
你可能想要这样的东西:
$jobrequests = preg_grep('/^jobrequestnumber\d+$/', array_keys($_GET)); // get matching key names
foreach($jobrequests as $jobrequest) {
$key = substr($jobrequest, 12); // extract the digit(s) from the end of the key name
...
}
可能需要将其作为变量传递,更像是使用函数和参数的OOP方法。我相信$\u POST/$\u GET变量的作用域仅限于发布到的页面。不可能,但存在真正的重复问题。请关闭并删除此项。这是URL变量,而不是名称变量,因此,谢谢您为他的部分preg\u gre与我共享一个链接p(“/^jobrequestnumber\d+$/”,数组键($\u GET))?