简体   繁体   English

表格过帐数据错误

[英]Form Post Data Error

I have created a short form which is supposed to take data from three text areas, and combine them. 我创建了一个简短的表单,该表单应该从三个文本区域中获取数据,并将它们组合在一起。 It seems that the output of my data is "0". 看来我的数据输出为“ 0”。 Any ideas why this much be so? 任何想法为何如此? Thanks in advance for the help. 先谢谢您的帮助。

<?php
function get_text() {
    $text = trim($_POST['one']);
    $textAr = explode("\n", $text);
    $textAr = array_filter($textAr, 'trim');

    $text2 = trim($_POST['two']);
    $textAr2 = explode("\n", $text2);
    $textAr2 = array_filter($textAr2, 'trim');

    $text3 = trim($_POST['three']);
    $textAr3 = explode("\n", $text3);
    $textAr3 = array_filter($textAr3, 'trim');

    return array($textAr, $textAr2, $textAr3);
}
?>

<form name="merge" method="POST">
    <textarea name="one" rows="10" cols="20"></textarea>
    <textarea name="two" rows="10" cols="20"></textarea>
    <textarea name="three" rows="10" cols="20"></textarea>
    <br /><input type="submit" name="done" value="Merge" /><br /><br />
    <textarea name="result" rows="10" cols="60">
    <?php 
    if(isset($_POST['done'])) {
        list($textAr, $textAr2, $textAr3) = get_text();
        for ($i=0; $i < count($textAr); $i++)
            for ($j=0; $j < count($textAr2); $j++)
                for ($k=0; $k < count($textAr3); $k++)
                    echo($textAr[$i] + $textAr2[$j] + $textAr3[$k]);
    }
    ?></textarea>
</form>

use . 使用. (dot) to concat a strings in php try change (点)在PHP中连接字符串尝试更改

echo($textAr[$i] + $textAr2[$j] + $textAr3[$k]);

to

echo $textAr[$i].$textAr2[$j].$textAr3[$k];

Your output is correct as i have tried your code in my local xamp server and it is working perfectly it merges the three values correctly. 您的输出是正确的,因为我已经在本地xamp服务器中尝试过您的代码,并且它可以正常工作,并且可以正确合并三个值。 you can check out the screenshot below 您可以查看下面的屏幕截图

在此处输入图片说明

The problem might be with your server , restarting might help you. 问题可能出在您的服务器上,重新启动可能会有所帮助。 Or try it with new browser other than the one you are using. 或尝试使用新的浏览器,而不是您正在使用的浏览器。

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

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