Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中使用名称变量?_Php - Fatal编程技术网

如何在php中使用名称变量?

如何在php中使用名称变量?,php,Php,您好,我正在使用传递给另一个php文件的值。然而,每次我尝试将name变量的值与下面的普通变量结合使用时,PHP都不会读取它 global $counterforlist; $counterforlist= 0; while ($row = mysql_fetch_array($result)){ $counterforlist = $counterforlist +1; echo "<td><input type= 'text' name = 'jobrequestnumb

您好,我正在使用传递给另一个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');?> 
global$counterforlist;
$counterforlist=0;
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);

看来你没有申报反存单

你为什么不做一个

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>"   ;

使用文件1,您可以准备一个包含以下字段的表单:

<input type='text' name='jobrequestnumberX'...

在第二个文件中,您是否在任何地方声明了
$counterforlist
?您是否将第一个文件包含在第二个文件中?(例如
include()
require()
或它们的
*.\u一次(…)
副本。)您非常容易受到SQL注入攻击,如果您还没有受到攻击,您将被黑客攻击。学习使用PDO或类似的准备/参数化查询来完全避免此问题。您也容易受到XSS攻击。始终使用
htmlspecialchars()
在HTML上下文中使用任意数据时。未定义索引:jobrequestnumber,您似乎没有声明计数器列表。是的,我确实包含了所有文件,并在代码上方声明了$counterforlist,但忘了在内容中包含该文件,抱歉。谢谢,但我正在尝试区分连续变量我不理解w你想要达到的目标是什么。为什么要使用不同名称的变量?我真的认为上面的代码片段会达到你想要的效果。你试过了吗?试一下(如果还没有的话)让我们知道它在何处/如何失败,以便我们可以修复:)谢谢,我试图使用保存在一个或多个名称变量中的多个变量。这就是为什么我使用while循环,当我尝试在第二个文件中使用它时,它无法正确读取它们,因为无法调用不同的变量名称或其他。因此我使用$counterforlist在另一个文件中使用特定行的信息并更新数据库。但用户单击的每个链接仅保存一行数据的信息。因此,文件2中处理的每个请求都对应于数据库中存储的一个实体。如果需要传递多个实体的值,请请求(我不明白为什么),您可以在文件1中使用不同的结构。是的,就是这样,我只想传输一行的信息,但我不知道如何从许多行中仅选择一行。例如)我从自动生成的信息行中选择了一行,如果要传递一行值,我需要一个计数器值或值来区分不同的值。job1,工作2,工作3,等等,好主意,谢谢
foreach ($_GET["jobrequestnumber"] as $key => $value){
   $jobrequestnumber=$value;
   $requestingcompany=$_GET["requestingcompany"][$key];
   $dateforService=$_GET["dateforService"][$key];

   // here update database
}
<input type='text' name='jobrequestnumberX'...