My code not working

everything ok I also got output but, my database in not update if any one able to find Problem in this code please help me.

 
<?php
 include("../includes/db.php");
 if(isset($_GET['edit_slider'])) {
	$get_id=$_GET['edit_slider'];
	
	$get_slider="select * from slide_bar where sl='$get_id'";
	

	
	$run_slider= mysqli_query($con , $get_slider);
	
	$row_slider=mysqli_fetch_array($run_slider);
	
		$sl=$row_slider['sl'];
		$img= $row_slider['img'];
		$msg= $row_slider['desc'];
		
 }
		

 
 ?>

<!-- content starter here -->
 <div class="content_wrapper"> 
 
 <div id="content_area">
 
 
<div>

<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
  <script>tinymce.init({ selector:'textarea' });</script>
  

 
 <form action="" method="post" enctype="multipart/form-data">
<table align="center" width="795" border="2" >
<tr align="center">
<td colspan="8"><h2>Update Slider </h2> </td>
</tr>

<tr>
<td align="right"><b>Image :</b></td>
<td><input type="file" name="image" /><img src="../img/slider/<?php echo $img ?>" width="60" height="60"/></td>
</tr>

<tr>
<td align="right"><b>Text Area :</b></td>
<td><textarea name="message" cols="20" rows="10" ><?php echo $msg ;?></textarea></td>
</tr>

<tr align="center" >
<td colspan="7"><input type="submit" name="update_post" value="Update Slide Now" /></td>
</tr>



</table>



</form>
 
 
 
 <!-- box ads end -->

 </div>
</div>
</div>
 
<!-- content end here -->

<!-- content end here -->
 
 <!--....................-->

 
 <?php 
if(isset($_POST['update_post'])) {
$update_id=$sl;
$msg= $_POST['message'];


$image=$_FILES['image']['name'];
$image_tmp=$_FILES['image']['tmp_name'];

move_uploaded_file($image_tmp,"../img/slider/$image");


$update_product="update slide_bar set desc='$msg',img='$image' where sl='$get_id'";

$run_update= mysqli_query($con, $update_product);


if ($update_product){
	echo "<script>alert('slide Has been update!')</script>";
echo "<script>window.open('index.php?view_slider','_self')</script>";


}	
}

	
	
	
	?>

ask for errors. mysqli_error()

and by the way, your code is open for everyone to delete your database. hint: SQL-Injection, prepared statements

I can’t see how you get a value in $get_id by the time you come to update your database values. It seems that you submit the form back to the same script with method="POST", so the first part of the PHP won’t execute because there are no $_GET variables there. But you then rely on $get_id which is only created inside that first bit of code. You also create another variable, called $update_id, which relies on another variable ($sl) that is created in the first bit of PHP, but then don’t use it anywhere.

I’m surprised that you don’t get error messages, or that when you dump the values of the variables as part of your debugging tests you don’t see that one of them is blank.

This seems a strange test to see if the query has worked:

if ($update_product){

$update_product in this case is the query string, so it will always return a true value in this test.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.