I have done this code in viewstudents.php the deletion process worked with the image but I’m not able to do the javascript part inside php inside the echo i mean can someone help me out. here is my code:
<?php session_start(); include("connection.php"); if(!isset($_SESSION['user'])) header("location:login.php"); $qry="SELECT * FROM studentinformation"; $result= mysqli_query($con,$qry) or die (mysqli_error($con)); echo "Welcome ".$_SESSION['user']; echo "<table border =1 width=80%><tr><td>FullName</td><td>Email</td><td>Password</td></tr>"; while($i = mysqli_fetch_array($result)){ echo "<tr>"; echo "<td>".$i['FullName']."</td>"; echo "<td>".$i['email']."</td>"; echo "<td>".$i['Password']."</td> "; echo "<td><a href=DeleteStudentAction.php?Key=".$i['ID']."onclick="return confirm('Are you sure?')" ><img src = delete-1432400-1211078.png style = width:35px;hight:20px;> </img> </a></td>"; echo "</tr>"; } echo "</table>"; ?>
it worked fine with the image but I want to have a confirmation prompt that’s not working can someone help me out please. Here is my php action for deletion from the database in DeleteStudentAction.php
I really appreciate if someone would help me out because I’m new to php. Thanks!
Advertisement
Answer
You haven’t got quotes around your href, try this:
while($i = mysqli_fetch_array($result)) { echo '<tr> <td>' . $i['FullName'] . '</td> <td>' . $i['email'] . '</td> <td>' . $i['Password'] . '</td> <td> <a href="DeleteStudentAction.php?Key=' . $i['ID'] . '" onclick="return confirm('Are you sure?')"> <img src="delete-1432400-1211078.png" style="width:35px; height:20px;" /> </a> </td> </tr>'; }