简体   繁体   中英

PHP - How do you get the content of an html input without submitting the form?

In my program, the href redirects to another page with the $id, and I am able to edit the row with that id from that page (signoutteacher.php). No I also want to be able to transfer the location from the input box, but I need a button to do so. Does anyone have an idea of how I could do both using only one button?

while ($row = mysqli_fetch_array($result)){
  $id = $row['id'];
  if ($row['status']== "In"){echo "<tr class='w3-hover-green w3-large'>";
    echo "<td width='10%'>".$row['name']."</td>";
    echo "<td width='10%'>".$row['surname']."</td>";
    echo "<td width='5%'>".$row['status']."</td>";
    echo "<td width='20%'><form action='Teacher.php' method='post'><input type='text' name='location'></form></td>";
    $location=$_POST['location'];
    echo "<td width='10%'>"."
    <a href='signoutteacher.php?myId=".$id."&myLocation=".$location."' class = 'w3-btn w3-input w3-green w3-round-jumbo'>Sign Out</a>
    </td>";
    echo "</tr>";

The table heading have already been printed out, and everything else works fine when not considering the location. The error message says that the index 'location' is not defined. I know that I need to submit the input, but how?

Instead of including the $id in the url, I created a form where the $id is a hidden input and sent that to the form along with the location. Now everything works fine.

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