php sorter script only outputting the same data even though i am asking it to do diffrent

爱⌒轻易说出口 提交于 2019-12-13 04:23:26

问题


okay so i have made the following script to sort some data i have in this format

0|1|2

heres my script (this now works)

    <html>
<body>
    <form method="post">
<div align="center"><textarea name="mp" cols="60" rows="10">0|1|2</textarea><br />

Delim: <input type="text" name="delim" value="|" size="1" />&nbsp;data1: <input type="text" name="mail" value="0" size="1" />&nbsp;data2: <input type="text" name="pwd" value="1" size="1" />&nbsp;
<input type="submit" value=" send " name="btn-submit" />
</div>
</form>
</body>
</html>
<?php

    if (isset($_POST['mp'], $_POST['delim'], $_POST['btn-submit'], $_POST['mail'], $_POST['pwd'])) {
        $mps = preg_split('/\r\n|\r|\n/', $_POST['mp']);

        // Create an array to store results
        $result_data = array();

        // Iterate over requests
        foreach ($mps as $mp) {
            $mp = explode($_POST['delim'], $mp);

            // Store the account details in variables
            $email = $mp[$_POST["mail"]];
                  $password = $mp[$_POST["pwd"]];
            // Prepare a reusable string
            $result_string = "" . $email .  " : " . $password . "";
                            // Add result to the array
            $result_data[] = $result_string;






}
// Store of results complete. We now display them.
        if (count($result_data)) {
            echo "<ul
    list-style-type: none;
>";
            foreach ($result_data as $result_data_entry) {
                echo "<li list-style: none;>" . $result_data_entry . "</li>";
            }
            echo "</ul>";
        }
}




?>

i would now like to save the results into a text file also any help would be brilliant .

i am writing this extra line as my post has way way too much code .


回答1:


You aren't using the data1 and data2 fields anywhere in your PHP.

I think instead of this:

list($email, $password) = $mp;

you need

$email = $mp[$_POST["mail"]];
$password = $mp[$_POST["pwd"]];

It's also worth noting that the values supplied in those two fields will be zero based.



来源:https://stackoverflow.com/questions/17681960/php-sorter-script-only-outputting-the-same-data-even-though-i-am-asking-it-to-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!