0

Hey everyone having some troubles here with an update statement. I want to update a value(scanISN) if it exists and show information updated and if it doesn't exist show an error right now it show information updated even if it doesn't exist. How would I do that?

<?php

        if(!isset($_POST['addMe'])){
        //show form
        include_once('View/Scan.html.php');
        }else{
        //process the form
        //connect to the database
        include('Model/DBAdapter.php');


        //values to store in RMA Database
        $receiveDate = date('Y-m-d');   
        $rmaStatus = "Received";
        $scanISN = htmlspecialchars($_POST['scanISN'], ENT_QUOTES, 'UTF-8');

        //create sql query
        $sql = ("UPDATE RMA SET Received_Date = '$receiveDate', RMA_Status = '$rmaStatus' 
                WHERE Unit_Serial_Number = '$scanISN'");

        $result = $connection->query($sql);
        if(!$result){
        //ISN Does not exist
        $output = "ISN does not exist please contact support";
        }else{
        $output = "RMA information updated.";
        }

        include('View/Scan.html.php');
}
1
Contributor
1
Reply
34
Views
4 Years
Discussion Span
Last Post by brandon66
0

or I have something like this but it coded wrong and doesn't work correctly

<?php

        if(!isset($_POST['addMe'])){
        //show form
        include_once('View/Scan.html.php');
        }else{
        //process the form
        //connect to the database
        include('Model/DBAdapter.php');


        //values to store in RMA Database
        $receiveDate = date('Y-m-d');   
        $rmaStatus = "Received";
        $scanISN = htmlspecialchars($_POST['scanISN'], ENT_QUOTES, 'UTF-8');
        $rmaNumber = htmlspecialchars($_POST['rmaNumber'], ENT_QUOTES, 'UTF-8');


        //create sql query
        $sql = ("UPDATE RMA SET Received_Date = '$receiveDate', RMA_Status = '$rmaStatus' 
                WHERE Unit_Serial_Number = '$scanISN'AND RMA_Number = '$rmaNumber'");

        $result = $connection->query($sql);



        $sql2 = ("SELECT Received_Date, RMA_Status FROM RMA WHERE Unit_Serial_Number = '$scanISN' AND RMA_Number = '$rmaNumber' "); 
        $result2 = $connection->query($sql2);

        $check1 = ['Received_Date'];
        $check2 = ['RMA_Status'];

        if($check1 = $receiveDate & $check2 = $rmaStatus) {
        // success
        $output = "RMA information updated.";
        } else {
         // error
         $output = "RMA does not exist please contact support";
}
            include('View/ScanOutput.html.php');
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.