HOW TO PREVENT FORM REFRESH ON GETTING REDIRECTION FROM ANOTHER PHP PAGE

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
shankarnstl
New php-forum User
New php-forum User
Posts: 4
Joined: Wed May 08, 2019 6:29 am

Wed May 08, 2019 6:50 am

1. I have placed select option box and two textboxes with datepickers for from date and to date to fetch opted value between two given values and I am getting the result display in the same page filesearch.php with added delete and update options for each displayed row.

2. I have placed delete query for a particular selected record in another page called filedelete.php with a form redirection to filesearch.php after completion of delete.

3. After clicking the delete button of a particular record in filesearch.php, the particular record is deleting from the mysql table and the values of datepicker textboxes vanishing.

4. The total displayed records in filesearch.php are getting disappeared after getting redirection form filedelete.php. Only disappearing not deleting. The selected record is successfully getting deleted.

5. I want to keep the remaining records to be shown after redirection.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 839
Joined: Mon Feb 22, 2016 5:52 pm

Wed May 08, 2019 8:03 am

If I read that correctly, you want to allow a user to delete a record from the database and then show the user what they have just deleted?

If so: you'll need to store the information separately, $_SESSION might be the answer.

shankarnstl
New php-forum User
New php-forum User
Posts: 4
Joined: Wed May 08, 2019 6:29 am

Wed May 08, 2019 8:36 am

hyper wrote:
Wed May 08, 2019 8:03 am
If I read that correctly, you want to allow a user to delete a record from the database and then show the user what they have just deleted?

If so: you'll need to store the information separately, $_SESSION might be the answer.
Thank you very much for response. Yes, The user to be redirected from the filedelete.php to filesearch.php and display remaining records after deleting the opted one.

Kindly guide me how to handle this. I tried to attach files, but .php files are not attaching. As I am new to this community I did not understand how to attach files.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 839
Joined: Mon Feb 22, 2016 5:52 pm

Wed May 08, 2019 2:51 pm

If you follow the link I gave and do some research on $_SESSION, you will find how to use it to keep the information on your page, but it does depend on exactly what you want to do, you may not need to use it at all.

To put your code on here, simply paste it into a code block using the </> button.

shankarnstl
New php-forum User
New php-forum User
Posts: 4
Joined: Wed May 08, 2019 6:29 am

Fri May 10, 2019 5:21 pm

In the filesearch.php

Code: Select all

<?php
//FOR RETAINING THE DATEPICKER VALUES ON CLICK OF SEARCH BUTTON OF THE PAGE
$frmdate=$_POST['frmdate'];
$todate=$_POST['todate'];
?>
</select> 
<input  type="text" id="myDatepicker" placeholder="Click to pick from date" name = "frmdate" autocomplete="off" value="<?php if(isset($frmdate)) {echo $frmdate;}?>"/> 
 <input  type="text" id="myDatepicker2" placeholder="Click to pick to date" name = "todate" autocomplete="off"  value="<?php if(isset($todate)) {echo $todate;}?>"/>    <br>
<br><input name="search" class="btn btn-primary" type="submit" value="SEARCH"/></center>
<!--the following data will be fetched and displayed-->
if(isset($_POST['search'])){
						$div=$_POST['list'];
						$frmdate=$_POST['frmdate'];
						$todate=$_POST['todate'];
						
						$q = "SELECT * FROM `filetrack` WHERE `sent_to`='$div' AND `sent_on` Between '$frmdate' and '$todate' order by `sent_on`";
					
					$query = mysqli_query($link,$q);
					
					while($res=mysqli_fetch_array($query)){
				?>
				
						<tr>
							<td><?php echo $res['file_no'];?></td>
							<td><?php echo $res['file_desc'];?></td>
							<td><?php echo $res['sent_to'];?></td>
							<td><?php echo $res['sent_on'];?></td>
							<td><?php echo $res['purpose'];?></td>
			<!--BUT AFTER CLICKING THE DELETE BUTTON QUERY IS EXECUTING FROM filedelete.php BUT AFTER GETTING REDIRECTION ALL INPUT VALUES ARE VANISHING.  I WANT TO HAVE REMAINING RECORD DISPLAY AFTER REDIRECTION TO filesearch.php-->
<td><button id="recorddelete" type="button"class="btn-danger btn"><a href="filedelete.php?id=<?php echo $res['id'];?>">Delete</a></button></td>	



<!--filedelete.php-->	
					<?php
	$link = mysqli_connect("localhost","root","");
	mysqli_select_db($link,"stores_bgts");
	
	$id = $_GET['id'];
	$q = "DELETE FROM `filetrack` WHERE id = $id";
	mysqli_query($link,$q);
	header('location:filesearch.php');

?>
My ultimate target is after clicking the delete button, I need to have the filesearch.php display with remaining records eliminating the deleted record. Kindly help me out.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 839
Joined: Mon Feb 22, 2016 5:52 pm

Sat May 11, 2019 8:57 am

What are you struggling with?

Your post doesn't mention any specific problem that you have, I can't help if you don't show what your problem is.

shankarnstl
New php-forum User
New php-forum User
Posts: 4
Joined: Wed May 08, 2019 6:29 am

Sat May 11, 2019 5:30 pm

The issue is,

When I press the Delete button, it is supposed to execute the delete query in filedelete.php and redirect to filesearch.php and display all the earlier data except deleted one.

But,

The delete query is executing and the already displaying records in filsearch.php are entirely vanishing / refreshing.

I need to fix this. Kindly guide me.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 839
Joined: Mon Feb 22, 2016 5:52 pm

Sun May 12, 2019 5:31 am

I already have, you can use $_SESSION or maybe pass details through $_GET.

Just to clarify, this is not a script writing service - help only is available - I do hope that you aren't expecting a script to be written for you.

Post Reply