Jump to content

Delete data error


Go to solution Solved by ginerjm,

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/314621-delete-data-error/
Share on other sites

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 by gw1500se
Link to comment
https://forums.phpfreaks.com/topic/314621-delete-data-error/#findComment-1594516
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/314621-delete-data-error/#findComment-1594518
Share on other sites

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');

Link to comment
https://forums.phpfreaks.com/topic/314621-delete-data-error/#findComment-1594529
Share on other sites

  • Solution

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  :)

Link to comment
https://forums.phpfreaks.com/topic/314621-delete-data-error/#findComment-1594538
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.