你好,我正在研究使用传递到其他 php 文件的值。然而,每次我尝试将 name 变量的值与下面的普通变量结合使用时,PHP 都不会读取它!
global $counterforlist;
$counterforlist= 0;
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');?>
这是调用这些值的另一个 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);
错误信息
Notice: Undefined index: jobrequestnumber in C:\xampp\htdocs\xampp\capstone\update_request.php on line 7
Notice: Undefined index: requestingcompany in C:\xampp\htdocs\xampp\capstone\update_request.php on line 8
Notice: Undefined index: dateforService in C:\xampp\htdocs\xampp\capstone\update_request.php on line 9
如果我再次声明变量,它不会从上一个 php 页面读取值。
你能帮我弄清楚我错过了什么吗:)
看来你没有声明柜台
你为什么不做一个
echo "<td><input type= 'text' name = 'jobrequestnumber[]' value =".$row['jobrequestnumber']."></td>" ; // results in the same jobrequestnumbers
echo "<td><input type= 'text' name = 'requestingcompany[]' value =".$row['requestingcompany']."></td>" ;//this too
echo "<td><input type= 'text' name = 'dateforService[]' value =".$row['dateforService']."></td>" ;