when I click submit it should change the text and update the row something is wrong there

Posted by Yousef Altaf on Stack Overflow See other posts from Stack Overflow or by Yousef Altaf
Published on 2012-09-24T09:25:03Z Indexed on 2012/09/24 9:37 UTC
Read the original article Hit count: 410

Filed under:
|
|

good morning programers, I have this small code which content a news control panel and I made a submit button there to active or inactive the news row so if I click on this button it should change if it's active it will be inactive it worked but there's something wrong there when I click on item one it updates the last on the table not the first on as it should do. here is the code that I use

<?php
$getNewsData="select * from news";
    $QgetNewsData=$db->query($getNewsData)or die($db->error);
    $count=mysqli_num_rows($QgetNewsData);
while($newsRow = mysqli_fetch_array($QgetNewsData)) {
$getActivityStatus=$newsRow['news_activity']; 
    switch($getActivityStatus){
    case 1: echo"<input style='color:red; font-weight:bold; background:none; border:0;' name='inactive' type='submit' value='?????' /><input name='inActive' type='hidden' value='".$newsRow['news_id']."'/>"; 
    break; 
    case 0: echo"<input style='color:green; font-weight:bold; background:none; border:0;' name='active' type='submit' value='?????' /><input name='Active' type='hidden' value='".$newsRow['news_id']."'/>"; break;}
    }
if(isset($_POST['inactive'])){
            $inActive=$_POST['inActive'];
            echo $inActive;
        $updateStatus="UPDATE news SET news_activity=0 WHERE news_id='".$inActive."' ";
        $QupdateStatus=$db->query($updateStatus)or die($db->error);
        if($QupdateStatus){ 
            }
        }

        if(isset($_POST['active'])){
            $Active=$_POST['Active'];
            echo $Active;
        $updateStatus="UPDATE news SET news_activity=1 WHERE news_id='".$Active."' ";
        $QupdateStatus=$db->query($updateStatus)or die($db->error);
        if($QupdateStatus){
        header("Location:CpanelHome.php?id=7"); 
            }
        }
    ?>

please any idea to solve this problem. Thanks, regards

© Stack Overflow or respective owner

Related posts about php

Related posts about forms