php sorter script only outputting the same data ev

2019-09-01 07:53发布

问题:

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.