简体   繁体   English

表单变量+提交按钮未与php串联

[英]form variable + submit button not concatenating with php

UPDATED: Examples added at end as requested: 更新:根据要求在末尾添加了示例:

Got a seemingly unique problem with concatenating form variables + the name of the button used to submit. 连接表单变量+用于提交的按钮名称出现了看似唯一的问题。

This works: 这有效:

$word="number"; $ word =“ number”; $number=1; $ number = 1; myalbum=$word.$number; myalbum = $ word。$ number;

echoing $myalbum gives "number1". 回声$ myalbum给出“ number1”。 No surprises there. 没有惊喜。

BUT if I POST the form to a php script with the intention of writing to file ONLY the data on row on which the button was pushed, I get problems. 但是,如果我将表单过帐到php脚本,而只打算将按下按钮的行上的数据写入文件,则会出现问题。

So, let's say I've got 10 rows, and the button for row 5 is pushed. 因此,假设我有10行,并按下了第5行的按钮。 If I get the script to echo what button was pushed ($button), I get "5" back. 如果我得到脚本以回显所按下的按钮($ button),则返回“ 5”。 If I get the script to echo what's in the box in row 5 (in this case, "$number5=5") then by echoing $number5 I get 5. 如果我让脚本回显第5行框中的内容(在本例中为“ $ number5 = 5”),则通过回显$ number5,我得到5。

But if I concatenate $number.$button, I get nothing, when I expect "number5". 但是,如果我串联$ number。$ button,当我期望“ number5”时,我什么也没得到。 And yet, if I concat any two parts of the submitted data, it works as expected. 但是,如果我合并提交的数据的任何两个部分,它将按预期工作。

I've been over the variables section at php.net, I've been over the w3 forms tutorials. 我看过php.net的变量部分,看过w3表单教程。 I've googled. 我用谷歌搜索。 I've stackoverflowed. 我堆栈溢出了。 I've checked and triple checked my spelling. 我检查了并拼写检查了三遍。

I even started from scratch - again, it's almost as if appending the value of the button kills the concatenation process. 我什至从头开始-再次,几乎就像追加按钮的值会终止串联过程一样。

UPDATED: 更新:

The output from the form: preset1=Name+of+preset+1&url1=http%3A%2F%2Fexample.com%2F1&preset2=Name+of+preset+2&url2=http%3A%2F%2Fexample.com%2F2&preset3=Name+of+preset+3&url3=http%3A%2F%2Fexample.com%2F3 来自以下形式的输出:预设1 =名称+的+预设+ 1&url1 = http%3A%2F%2Fexample.com%2F1&preset2 =名称+的+预设+ 2&url2 = http%3A%2F%2Fexample.com%2F2&preset3 =名称+ of + preset + 3&url3 = http%3A%2F%2Fexample.com%2F3

The code for the form handler: 表单处理程序的代码:

<?php
$myFile = "test.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Preset: " . $preset .  " - Title:" . $title . $submitButton . " - Submit Button:" . $submitButton . "\n"; 
fwrite($fh, $stringData);
fclose($fh);
?>

The output from the above: Preset: 3 - Title:3 - Submit Button:3 上面的输出:预设:3-标题:3-提交按钮:3

So, we know it knows what buttons has been pressed. 因此,我们知道它知道按下了哪些按钮。 But not the output I expected. 但不是我期望的输出。

But if I change the line to $stringData = "Preset: " . 但是,如果我将行更改为$ stringData =“ Preset:”。 $preset3 . $ preset3。 " - Title:" . “-标题:”。 $title3 . $ title3。 " - Submit Button:" . “-提交按钮:”。 $submitButton . $ submitButton。 "\\n"; “ \\ n”;

then I get, as expected: Preset: Name of preset 3 - Title: http://www.example.com/3 - Submit Button:3 然后按预期方式得到:预设:预设3的名称-标题: http : //www.example.com/3-提交按钮:3

But of course, this is no good. 但是,当然,这不好。 I understood that if $preset.$submitButton would be the same as $preset3 if submitButton was 3. 我知道,如果commitButton为3,则$ preset。$ submitButton与$ preset3相同。

Oh, and I've also tried $thepreset='$title' . 哦,我也尝试过$ thepreset ='$ title'。 $submitbutton; $ submitbutton; and then using that - all I get is "Title:$title" 然后使用它-我得到的只是“标题:$ title”

This line: 这行:

 "$thepreset='$title'"

returns "Title:$title" as expected - you have $title inside quotes, so it isn't recognized as a var. 会按预期返回“标题:$ title”-您在引号内包含$ title,因此不会将其识别为var。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM