sk2learnphp Posted March 24, 2022 Share Posted March 24, 2022 Hi, I am new to this forum and a new learner of PHP.I am learning it from various web resources. I have tried to create a simple database application using PHP Mysql.Here during delete operation I have used one confirmation dialog box whether to delete a record or not? For this I am using javascript.Here may be for some error, record is deleted whatever be the user response.Can anyone suggest any solution to this problem. for_phpforum.txt Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 24, 2022 Share Posted March 24, 2022 (edited) You need to post your code here not make people go to a 3rd part web site. Also if you suspect the problem is in Javascript then post in the Javascript forum. When you do post use the code icon (<>) in the top menu for your code and select the appropriate code type. Edited March 24, 2022 by gw1500se Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 24, 2022 Share Posted March 24, 2022 If you are just starting out with PHP and database access I (and many others here) would strongly suggest that you use the PDO interface to access your data instead of mysqli. It is much easier to use/code and provides an easy way of doing whatever you need to to with your data. And as for your post. Yes - always post your code here. And not an 'image' of your code but the real thing so that we can easily read it and even copy and paste it into our own editor to work with it. Use the <> icon at the top of this window to place all code in its own window in the middle of your post. Quote Link to comment Share on other sites More sharing options...
sk2learnphp Posted March 24, 2022 Author Share Posted March 24, 2022 Thanks for the response.I am sending the code using the <> icon at the top of this window error_reporting(E_ALL); Part of admin_deshboard.php <!-- #Code for delete student details---Start--> <?php if(isset($_POST['delete_student'])) { ?> <center><br><br> <h5>Enter the Roll No to Delete Student</h5><br> <form action="delete_student.php", method="post"> Roll No: <input type="text" name="roll_no"> <input type="submit" name="search_by_roll_no_for_delete" value="Delete"> </form> </center> <?php } ?> delete_student.php <script type="text/javascript"> if(confirm("Are you sure want to delete ?")) { document.write("<?php $connection = mysqli_connect("localhost","root",""); $db = mysqli_select_db($connection,"sms"); $query = "delete from student where roll_no = $_POST[roll_no]"; $query_run = mysqli_query($connection,$query); ?>"); window.location.href = "admin_dashboard.php"; } else { window.location.href = "admin_dashboard.php"; } </script> ini_set('display_errors', '1'); Quote Link to comment Share on other sites More sharing options...
Solution ginerjm Posted March 24, 2022 Solution Share Posted March 24, 2022 I believe that your JS should be in the admindashboard script not the delete script. <script type='text/javascript'> function confirmDelete() { if (confirm('Are you sure you want to delete this record?')) return true; else return false; } Use the above function like this: <input type="submit" name="search_by_roll_no_for_delete" onclick='return confirmDelete()' value="Delete"> You can use shorter names for your fields. Saves on typing Quote Link to comment Share on other sites More sharing options...
sk2learnphp Posted March 24, 2022 Author Share Posted March 24, 2022 Thank you ginerjm. The code is working properly.It saves lot of my time.👏 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.