简体   繁体   中英

button to send multiple data to the database (php, ajax)

I send the data from the database to the screen with foreach.I do not see any results when I click the button.where do i make mistakes i ask you to help

 <table class="table">
   <thead class="thead-dark" align="center"  >

   <th >id</th>
   <th >EğitimAdı</th>
   <th >Adres</th>
   <th >Onay </th>
   </thead>
   <tbody>
    <form  id="form1" action="" method="post"> 
  <?php $i=1; foreach($dbb as $ac){ ; ?>
       <tr align="center" >  
           <td > <?php echo $ac[0]; ?> </td>
           <td > <?php echo $ac[1]; ?></td>
           <td   align="center"> <iframe width="360" height="115" src="<?php echo $ac[2]; ?>" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen  ></iframe></td>
            <td >
             <button type="button" value="<?php echo $ac[0]; ?>" id="gonder"  onclick="gonder('this.val()')">İzledim</button>  
            </td>
       </tr>
  <?php $i++; } ?>
  </form> <p></p>
 </tbody>

   </table>

gonder.js send to the database

   function gonder(deger){
        $.ajax({
        type:"post",
        url:"isleme.php",
        data:deger,
        success:function(cevap) {
        $("p").text(cevap);
        }
        })

}

isleme.php to view the screen

<?php 
   $b=$_POST['deger'];
   echo $b;
    ?>

First you're missing parentheses:

onclick="gonder" has to be onclick="gonder()"

Secondly variable "deger" is empty because #id doesn't exist, try changing to:

var deger = $("#gonder").val();

I noticed you are iterating and having same id for all the elements. Ideally id should be unique in each of the document.

You can do either of the below:

  1. prepare and have unique id for each iterative element.
  2. Try removing id element since you are not dependent on click using id.

Please let me know, if it helps?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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