-1

How to run php scripts on button click? I have made a list of upcoming workshops and made a button to register for the workshops.On clicking apply button, i want to insert details of that student in the database. Here is my code.

<?php

    include('connect_db.php');
    $query = "select * from workshop";
    $data = mysqli_query($con,$query);

    echo "<table>";

    while($row=mysqli_fetch_array($data, MYSQLI_ASSOC))
    {
        $wid = $row['Workshop_id'];
        $wname = $row['Workshop_name'];
        $inst = $row['Instructor'];
        $dt = $row['Date'];
        $tm = $row['Time'];

        echo "<tr><td>$wname</td>";
        echo "<td>$inst</td>";
        echo "<td>$dt</td>";
        echo "<td>$tm</td>";

        echo "<td><button type='button' class = 'btn-primary' id = 
            'apply'>Apply</button></td>";

    }
    echo "</table>";
?>
tech2017
  • 1,806
  • 1
  • 13
  • 15
Raveena_C
  • 1
  • 2

1 Answers1

0

Spend some time researching Ajax.

The basic method is:

  • The user clicks a button
  • A JavaScript function is triggered (jQuery is great for this)
  • Your PHP code is called
  • You can process the output of the script (echo's, errors, etc).

Which is exactly what you need.

W3Schools has a great tutorial on this.

mfisher91
  • 805
  • 1
  • 8
  • 23