Home > Software engineering >  how to send data with php?
how to send data with php?

Time:08-16

I'm trying to send player id to delete and update page and it doesn't send it.

i'm adding my table body here.

              <tr>
                <td><img src="<?php echo $readRow['Photo']; ?>" width='64px'></td>
                <td> <?php echo$readRow['ID']; ?></td>
                <td> <?php echo$readRow['Fname']; ?></td>
                <td> <?php echo $readRow['Lname']; ?></td>
                <td> <?php echo$readRow['Age']; ?></td>
                <td> <?php echo$readRow['Email']; ?></td>
                <td> <?php echo$readRow['Phone']; ?></td>
                <td><a href='update.php?id=$readRow[ID]' data-toggle="modal" data- 
                        target="#editplayer" class = 'btn btn-success'>Edit</a>
                <a href="delete.php" name = "Delete"  class = 'btn btn-danger'>Delete</a></td>
              </tr>
              <?php
              }
              ?>

please help.

CodePudding user response:

You need <?php echo ?> around $readRow[ID]. And you need to put that into the delete.php URL as well.

              <tr>
                <td><img src="<?php echo $readRow['Photo']; ?>" width='64px'></td>
                <td> <?php echo$readRow['ID']; ?></td>
                <td> <?php echo$readRow['Fname']; ?></td>
                <td> <?php echo $readRow['Lname']; ?></td>
                <td> <?php echo$readRow['Age']; ?></td>
                <td> <?php echo$readRow['Email']; ?></td>
                <td> <?php echo$readRow['Phone']; ?></td>
                <td><a href='update.php?id=<?php echo $readRow['ID']; ?>' data-toggle="modal" data- 
                        target="#editplayer" class = 'btn btn-success'>Edit</a>
                <a href="delete.php?id=<?php echo $readRow['ID']; ?>" name = "Delete"  class = 'btn btn-danger'>Delete</a></td>
              </tr>
              <?php
              }
              ?>

CodePudding user response:

You can just add your id to be deleted as a GET parameter

 <a href="delete.php?id=<?php echo $readRow['ID']; ?>" name = "Delete"  class = 'btn btn-danger'>Delete</a></td>

However, I suggest you stay away from GET and use POST method, which is much more secure.

<form action="delete.php" method="post">
<tr>
<td><img src="<?php echo $readRow['Photo']; ?>" width='64px'> 
// ...other td elements
</tr>
</form>

CodePudding user response:

You need to enclose player id with <?php and ?> (PHP start and end tag respectively) as given below:

<a href='update.php?id=<?php echo $readRow[ID]; ?>' data-toggle="modal" data-target="#editplayer" class = 'btn btn-success'>Edit</a>
<a href="delete.php?id=<?php echo $readRow[ID]; ?>" name = "Delete"  class = 'btn btn-danger'>Delete</a>
  • Related