codeSeven
codeSeven

Reputation: 469

get value mysql count and save to table

What i have here is to get the value of my count and save to my table but it's not working. I just want to get the count value, can you help me ? i will appreciate any answer. No problem with displaying with count but only in saving in my table.

    <form method="POST">
        Date : <input type="text" value="<?=$p_date?>" name="datereceived" />
        <input type="submit" name="save" value="save">
    </form>

PHP

    <?        
        $sql="SELECT allinvty3.*, barcode.* ,  sample.*, count(barcode.itemcode) as icount  
    from barcode INNER JOIN sample on barcode.itemcode = sample.in_code INNER JOIN allinvty3 on 
    barcode.itemcode = allinvty3.in_code WHERE barcode.refnumber = '$temp'
 GROUP BY barcode.itemcode";

        $result = $conn->query($sql);
        while($row = $result->fetch_assoc()) {
            $icount = $row['icount'];
        }

        if(isset($_POST['save'])){
            $sql = "UPDATE barcode SET datereceived ='$p_date', actualacount = '".$icount."', status='COMPLETE' WHERE status='PENDING'";   
            $conn->query($sql) ;     
        } 
    ?>

Upvotes: 3

Views: 251

Answers (1)

mamosek
mamosek

Reputation: 316

Because you have an error in your SQL. Try this

$sql = "UPDATE barcode SET
        datereceived ='".$p_date."' , actualacount ='".$icount."' ,
        status='COMPLETE'  WHERE status='PENDING'";

Upvotes: 3

Related Questions