thenature4u Posted December 10, 2007 Share Posted December 10, 2007 THIS IS MY CODE........ <?php $con = mysql_connect("localhost","root",""); mysql_select_db("mytest", $con); $sql="select qid,uid,fname,mailid,query,date from uqueries"; $res= mysql_query($sql) or die(mysql_error()); echo "<br><br><br><br><br>"; include "services.html"; echo "<br><br><br><br><br>"; echo "<center>"; echo "<table border=1> <tr> <th>qid</th> <th>name</th> <th>query</th> <th>date</th> <th>Delete Query</th> <th>Delete User</th> </tr>"; while($row = mysql_fetch_array($res)) { ?> <script type="text/javascript"> <!-- function confirmation() { var answer = confirm("Delete Query <? echo $row['qid']; ?> ?") if (answer){ alert("Query Deleted") window.location = 'quedelete.php?qid=<?php echo $row['qid'] ?>'; } else{ alert("No action taken") } } function confirmat() { var answer = confirm("Delete User <? echo $row['uid']; ?> ?") if (answer){ alert("User Deleted") window.location = 'usdelete.php?uid=<?php echo $row['uid'] ?>'; } else{ alert("No action taken") } } //--> </script> <?php echo "<tr>"; echo "<td>" . $row['qid'] . "</td>"; echo "<td>" . $row['fname'] . "</td>"; echo "<td>" . $row['query'] . "</td>"; echo "<td>" . $row['date'] . "</td>"; ?> <td> <a href="javascript:confirmation()"> Delete query</a> </td> <td> <a href='javascript:confirmat()'> Delete User</a> </td> </tr> <?php } ?> </table> </center> IAM DEVELOPING THIS FOR ADMIN PURPOSE. HE CAN DELETE A QUERY OR USER... EVERY QUERY AND USER ARE HAVING THE UNIQUE VALUES......I WOULD LIKE TO DELETE A QUERY OR USER BY USING HIS UNIQUE ID. THE ADMIN HAS TO CONFIRM BEFORE DELETING.. HERE MY ERROR IS WHENEVER IAM DELETING A QUERY, THE VALUE OF $qid IS ALWAYS THE LAST VALUE, WHICH COME FROM THE DATABASE. IF SUPPOSE IN uqueries(table name) TABLE i have 12,13,34,6,78 and 23 are there, when i am going to delete a query always the $qid value is 23 only(last value).. where is the error....... Link to comment https://forums.phpfreaks.com/topic/80991-solved-using-javascript-confirm-box-with-php/ Share on other sites More sharing options...
JacobYaYa Posted December 10, 2007 Share Posted December 10, 2007 The problem is your have x JavaScript functions all with the same name (I believe). I haven't used JavaScript within the body tags for like 2 years...can't remember exactly how they work. Make your functions like this at the top of your page (no mass of JavaScript in the body)...also make a reusable function.. function confirmation(id) { var answer = confirm("Delete Query "+id+"?") if (answer){ alert("Query Deleted") window.location = 'quedelete.php?qid='+id; } else{ alert("No action taken") } } and then change your hrefs to add in the row id into the function. EDIT: Example echo '<a href="javascript:confirmation('.$row['id']'.)"> Delete query</a>'; Just noticed you have some crazy BB tags in that code also like you open an anchor with <a> then try close it with [/url]. Link to comment https://forums.phpfreaks.com/topic/80991-solved-using-javascript-confirm-box-with-php/#findComment-410885 Share on other sites More sharing options...
thenature4u Posted December 10, 2007 Author Share Posted December 10, 2007 i changed my code to like this..... still iam getting error like this.... Delete query undefined why iam unable to retreve the value of qid in function confirmation...... function confirmation(qid) { var answer = confirm("Delete Query "+qid+" ?") if (answer){ alert("Query Deleted") window.location = 'quedelete.php?qid='+qid; } else{ alert("No action taken") } } <a href="javascript:confirmation()(<? echo $row['qid']; ?>)"> Delete query</a> Link to comment https://forums.phpfreaks.com/topic/80991-solved-using-javascript-confirm-box-with-php/#findComment-410896 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.