0

I'm doing some unpaid work for our elementary school an looking for an Solution to pass an JS result to an php array...

$('.__results__`lastname [type="checkbox"]:checked').each( (indx, el) => {

        let name = $(el).parents('.__results__lastname').attr('data-name'),
        html += `
            <tr class="_lastnames_total">
                <td class="leftReview"><b>Lastname: <span >${name}</span></b></td>
            </tr>
        `;

The result of $(name) must be passed to php as an array

$postfields = array (
"username" => USER,
"password" => md5(PASS),
"action" => 'addlastnames',
"responsetype" => "json",
"lastname" => array('lastname1', 'lastname2', 'lastname3', ),
);

and i have no idea... any help would be awesome!

  • Set up a PHP script that receives an AJAX request from JavaScript with the data you outlined above, then process as your requirements dictate. – esqew Dec 04 '20 at 12:08
  • 2
    Possible canonical duplicate of [How do I pass JavaScript variables to PHP?](https://stackoverflow.com/questions/1917576/how-do-i-pass-javascript-variables-to-php) – esqew Dec 04 '20 at 12:09
  • 2
    Normally I would treat a question such as this with a level of scorn usually reserved for members of Congress, but since I get that you're doing unpaid work in a field that isn't yours for a presumably good cause I'll do you a solid. There are two ways: [submit a form](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form), or make an [XHR request](https://developer.mozilla.org/en-US/docs/Glossary/XHR_(XMLHttpRequest)). I'd go with the former in your case. – Jared Smith Dec 04 '20 at 12:09
  • 2
    You probably shouldn't be using MD5 for password hashing, **especially without proper salting**; [MD5 is known to be more vulnerable to attacks](https://security.stackexchange.com/questions/19906/is-md5-considered-insecure) than most modern hashing algorithms. For your users' and your data's sake, **please** consider a more modern/secure algorithm like `bcrypt`. – esqew Dec 04 '20 at 12:10
  • 1
    ...not to mention there's no salt. – Jared Smith Dec 04 '20 at 12:11
  • In PHP it's best to use the `password_hash`/`password_verify` methods for password hashing – Matt Dec 04 '20 at 12:13

0 Answers0