Hi Friends please tell me where I am wrong cause the database is still unchanged even though update query is executed successfully Thank you
here is the form code
echo'<form action="processor.php" method="post" id ="post_form">';
echo '<input type="hidden" name= "status" id="status" value="">';
$upload_arr=array("1");
foreach($upload_arr as $upload_id)
{
echo '<input type="button" name="accept-<?=$upload_id?>" value="accept" onclick="submit_this(this.name)"/><br>';
echo '<input type="button" name="reject-<?=$upload_id?>" value="reject" onclick="submit_this(this.name)"/><br>';
echo '<input type="button" name="saccept-<?=$upload_id?>" value="saccept" onclick="submit_this(this.name)"/><br>';
echo '<input type="button" name="sreject-<?=$upload_id?>" value="sreject" onclick="submit_this(this.name)"/><br>';
}
echo '</form>';
Note :here i have used $upload_id a php variable which has row[upload id] i.e. it is like accept 1,reject1,saccept1 ans sreject1 for first image and for second image it is accept2 reject2 and so on
Now the code for processor.php
$status_pass = isset($_POST['status'])?$_POST['status']:NULL;
if(!empty($status_pass)){
$status_arr = explode('-', $status_pass);
$action = $status_arr[0];
$upload_id = $status_arr[1];
if($action == 'accept'){
$status = 1;
}
if($action == 'reject'){
$status = 2;
}
if($action == 'saccept'){
$status = 3;
}
if($action == 'sreject'){
$status = 4;
}
echo $status;
$sql="UPDATE upload SET status='$status' where upload_id = '$upload_id' ";
echo "update success";
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
}
in your form
<form action="processor.php" method="post" id ='post_form'>
<input type="hidden" name= "status" id="status" value="">
<?php
foreach($upload_arr as $upload_id){
?>
<input type="button" name="accept-<?=$upload_id?>" value="accept" onclick='submit_this(this.name);'/><br>
<input type="button" name="reject-<?=$upload_id?>" value="reject" onclick='submit_this(this.name);'/><br>
<input type="button" name="saccept-<?=$upload_id?>" value="saccept" onclick='submit_this(this.name);'/><br>
<input type="button" name="sreject-<?=$upload_id?>" value="sreject" onclick='submit_this(this.name);'/><br>
<?php
}
?>
</form>
<script>
function submit_this(name){
document.getElementById('status').value = name;
document.getElementById('post_form').submit();
}
</script>
in you php file
<?php
$status_pass = isset($_POST['status'])?$_POST['status']:NULL;
if(!empty($status_pass)){
$status_arr = explode('-', $status_pass);
$action = $status_arr[0];
$upload_id = $status_arr[1];
if($action == 'accept'){
$status = 1;
}
if($action == 'reject'){
$status = 2;
}
if($action == 'saccept'){
$status = 3;
}
if($action == 'sreject'){
$status = 4;
}
$sql="UPDATE upload SET status='$status' where upload_id = '$upload_id' ";
//execute sql here
}
?>
can you please replace $_POST["accept'.$upload_id.'"] this with $_POST["accept".$upload_id]
Don't use '' quotes for $upload_id input tag, It will work then properly
there's some problems of your code
First
if you want to multiple submit form, the type shuold be button, you can use javascript to contorl submit form, and before submit, you can also pass some value to a hidden input field, as your example, you can set hidden input value = "accept'.$upload_id.'"
Second
in your php file,
$sql="UPDATE upload SET status='1'";
has no where condition, of course, this will update all your records.