How to do INSERT button?

There is a database, it has 2 tables: users and new-user (for example)
on a separate page, I conclude all users for their login (the login field from the users table)

anything else
the insert button (when pressed, it inserts the login field and "something" to the table new-user)

tried to do it all through the form, but the record goes only to the 1st row, and users assume 100
Actually a question how to make a button or checkbox that was written in the table, or as something to note first of all the checkboxes, and then click all at once to record
June 8th 19 at 17:21
1 answer
June 8th 19 at 17:23
Chet little code, Yes the meaning is clear...

Hint: input of the form
<input type="text" name="username[]" value="somename">
inserted repeatedly, on the server side will be interpreted as an array which you can loop through and get the entire list of your 100 rows. If the form post method, respectively, in the server's $_POST['username'][0] = 'somename';
now I'm using ajax passing data to the handler
$("#check-sight").submit(function() { //Change
 var th = $(this);
 type: "POST",
 url: "/update_user.php", //Change
 data: th.serialize()
 }).done(function() {
 $('#gratz').delay(3500).fadeOut(function() {
 setTimeout(function() {
 // The Done Functions
 }, 1000);
 return false;

and in the handler
if (isset($_POST['data']))
$data = $_POST['data'];
$fam = $_POST['family'];
$check = $_POST['user-check'];

$result122 = mysql_query("INSERT new user SET login ='$fam', data = '$data', usercheck = '$check'",$db);
echo "Done!";}
- Reginald.Pouros commented on June 8th 19 at 17:26
The form itself
<form id="check-sight">
 <input type="text" name="data" value="2018-01-29" hidden>
 <input type="text" name="family" value="$myrow[login]" hidden>
 <input type="text" name="user-check" value="1" hidden>
- Reginald.Pouros commented on June 8th 19 at 17:29
the code is a nightmare, suitable only to show how not to do it.
1) mysql_query is outdated 5 or 10 years as, at least use mysqli.
2) with this insert is hacking / breaking a base case of two requests to the server.
3) echo "Done!" you do in any case is called, why is it there?

otherwise - if the form will include all fields specified by me in the response by the server just have to foricet on the necessary fields, Ajax not change anything you will need, just in the handler. - lily.Kozey commented on June 8th 19 at 17:32
can handler code? - Reginald.Pouros commented on June 8th 19 at 17:35
<form id="check-sight">
 <input type="text" name="data[]" value="2018-01-29" hidden>
 <input type="text" name="family[]" value="<?=$myrow['login1']?>" hidden>
 <input type="text" name="user-check[]" value="1" hidden>

 <input type="text" name="data[]" value="2018-01-22" hidden>
 <input type="text" name="family[]" value="<?=$myrow['login2']?>" hidden>
 <input type="text" name="user-check[]" value="2" hidden>

 <input type="text" name="data[]" value="2018-01-23" hidden>
 <input type="text" name="family[]" value="<?=$myrow['login3']?>" hidden>
 <input type="text" name="user-check[]" value="2" hidden>

 if(!empty($_POST['data']) && !empty($_POST['family']) && !empty($_POST['user-check'])){
 foreach($_POST['data'] as $key=>$val){
 $sql = "INSERT new user 
 SET `login` ='$_POST['family'][$key]', 
 `data` = '$_POST['data'][$key]', 
 usercheck = '$_POST['user-check'][$key]'";

Code is about the same curve as yours, so you can not write, the point is how the server will look like your data. In production this should not be used. - lily.Kozey commented on June 8th 19 at 17:38
, localhost/new.php?data%5B%5D=2018-01-29&family%5B%...

record in the database is still there - Reginald.Pouros commented on June 8th 19 at 17:41
I certainly glad that you gave me access to the famous hosting localhost, but, unfortunately, to see what you have there I can not )
Also, apparently your Ajax is not triggered, and triggered just recognize submit the form. For proper operation of the JavaScript the first line should be rewritten:
$("#check-sight").submit(function(e) { //Change
 var th = $(this);
- lily.Kozey commented on June 8th 19 at 17:44

Find more questions by tags MySQLPHP