Jump to content

brandon66

Members
  • Posts

    23
  • Joined

  • Last visited

Posts posted by brandon66

  1. you should look into jquery ajax its fairly easy. heres an example. Other suggestions for you is to use PDO or MySQLi for your php

    <?php
    // check that $_GET["str"] exists (ajax request has started)
    if(isset($_GET["str"]))
    {
        mysql_connect('localhost', 'root', '');
        mysql_select_db("sample");
    
    
        $str = mysql_real_escape_string($_GET['str']);
    
    
        $sql= "SELECT * FROM user WHERE id = '".$str."'";
    
    
        $result = mysql_query($sql);
    
    
        echo "<table border='1'>
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Age</th>
      </tr>";
    
    
        while($row = mysql_fetch_array($result))
        {
            echo "<tr>";
            echo "<td>" . $row['FirstName'] . "</td>";
            echo "<td>" . $row['LastName'] . "</td>";
            echo "<td>" . $row['Age'] . "</td>";
            echo "</tr>";
        }
        echo "</table>";
         
        mysql_close();
        exit; //We only need to echo out the data we need for the request (this will be the response)
    }
    ?>
    <html>
    <head>
        <script src="//code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
        <script type="text/javascript">
          $(document).ready(function(){  
           
            $('#users').change(function(){
             var user = $('#users').val();  
               showUser(user);
           });         
          });
            function showUser(str){
                if (str === "") {
                    //hide the div
                    $('#txtHint').hide();
                }else{
                //send str to php and get back data
                $.post('getuser.php', {str: str}, function(data)
                {
             //output data into the empty div
            //this could also be your txthint div
            $('div#table').html(data);           
        });
            }
        }
        </script>
    </head>
    <body>
        <form>
            <select name="users" id="users">
                <option value="">Select a person:</option>
                <option value="1">Peter Griffin</option>
                <option value="2">Lois Griffin</option>
                <option value="3">Glenn Quagmire</option>
                <option value="4">Joseph Swanson</option>
            </select>
        </form>
        <br/>
        <div id="txtHint">
            <b>Person info will be listed here.</b>
        </div>
        <div id="table"></div>
    </body>
    </html>
  2. So you want to refresh the page with Ajax instead of the meta tag?

     

    maybe something like this  

    <script type="text/javascript">// <![CDATA[
    $(document).ready(function() {
    $.ajaxSetup({ cache: false }); // This part addresses an IE bug.  without it, IE will only load the first number and will never refresh
    setInterval(function() {
    $('#divToRefresh').load('/image/path/here');
    }, 3000); // the "3000" here refers to the time to refresh the div.  it is in milliseconds. 
    });
    // ]]></script>
    
  3. How about something like this 

    <promo1>D123OO</promo1>
    <promo2>M876TT</promo2>
    <promo3>B765DC</promo3>
    <promo4>LO122M</promo4>
    
    

    I beleive it can be done like this also

    <promo>D123OO</promo>
    <promo>M876TT</promo>
    <promo>B765DC</promo>
    <promo>LO122M</promo>
    
    //Then you can reference it like
    
    $xml->customers->promo[1];
    $xml->customers->promo[2];
    $xml->customers->promo[3];
    $xml->customers->promo[4];
    
  4. Alright i am using PHP,Jquery, and MySql for this application its like an employee in/out status board with notes. I threw it together pretty quick just wondering if any would optimize it for me or tell me how i can optimize it. (like i said i just threw it together it works but the code its ugly!!)

     

     

    attached is the database i use for it and the application

     

    Will be very thankful for the help.

    Status backup 11-20-2013.zip

  5. ended up fixing it with this!!

    <?php
    
         //connect to database
         include '../../Model/DBAdapter.php';
    
    
        $aColumns = array( 'RMA_Number', 'Person_Calling', 'Company_Name', 'Unit_Serial_Number', 'CONCAT(e.Employee_First_Name, " ", e.Employee_Last_Name)',
                            'Call_Date','Received_Date','RMA_Status','Reason_For_Return','Notes','New_Install',
                            'New_Unit_Serial_Number', 'Terminal_ID','Account_Number','Account_Name');
         
        /* Indexed column (used for fast and accurate table cardinality) */
        $sIndexColumn = "RMA_Number";
         
        /* DB table to use */
        $sTable = "RMA";
        
        //Join to use
       $sJoin = ' JOIN Companies ON RMA.Company_ID  = Companies.Company_ID';
       $sJoin .= ' JOIN Employees e ON RMA.Employee_ID  = e.Employee_ID';
    
       
        /*
         * Paging
         */
        $sLimit = "";
        if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
        {
            $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ".
                intval( $_GET['iDisplayLength'] );
        }
         
         
        /*
         * Ordering
         */
        $sOrder = "";
        if ( isset( $_GET['iSortCol_0'] ) )
        {
            $sOrder = "ORDER BY  ";
            for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
            {
                if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
                {
                    $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
                        ".($_GET['sSortDir_'.$i]==='asc' ? 'asc' : 'desc') .", ";
                }
            }
             
            $sOrder = substr_replace( $sOrder, "", -2 );
            if ( $sOrder == "ORDER BY" )
            {
                $sOrder = "";
            }
        }
         
         
        /*
         * Filtering
         * NOTE this does not match the built-in DataTables filtering which does it
         * word by word on any field. It's possible to do here, but concerned about efficiency
         * on very large tables, and MySQL's regex functionality is very limited
         */
        $sWhere = "";
        if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
        {
            $sWhere = "WHERE (";
            for ( $i=0 ; $i<count($aColumns) ; $i++ )
            {
                if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" )
                {
                    $sWhere .= $aColumns[$i]." LIKE '%".  htmlspecialchars( $_GET['sSearch'] )."%' OR ";
                }
            }
            $sWhere = substr_replace( $sWhere, "", -3 );
            $sWhere .= ')';
        }
         
        /* Individual column filtering */
        for ( $i=0 ; $i<count($aColumns) ; $i++ )
        {
            if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
            {
                if ( $sWhere == "" )
                {
                    $sWhere = "WHERE ";
                }
                else
                {
                    $sWhere .= " AND ";
                }
                $sWhere .= $aColumns[$i]." LIKE '%".  htmlspecialchars($_GET['sSearch_'.$i])."%' ";
            }
        }
         
         
        /*
         * SQL queries
         * Get data to display
         */
        $sQuery = "
            SELECT SQL_CALC_FOUND_ROWS " . str_replace(" , ", " ", implode(", ", $aColumns)) . "
            FROM   $sTable
            $sJoin
            $sWhere
            $sOrder
            $sLimit
        ";
    try {
        $rResult = $connection->query($sQuery);
    } catch (PDOException $e) {
        $error = 'Error getting data: ' . $e->getMessage();
        echo $error;
        exit();
    }
    
    /* Data set length after filtering */
        $sQuery = "
            SELECT FOUND_ROWS()
        ";
        try{
        $rResultFilterTotal = $connection->query($sQuery);
        $aResultFilterTotal = $rResultFilterTotal->fetch();
        $iFilteredTotal = $aResultFilterTotal[0];
        }catch (PDOException $e) {
        $error = 'Error getting found rows: ' . $e->getMessage();
        echo $error;
        exit();
    }
        /* Total data set length */
        $sQuery = "
            SELECT COUNT(".$sIndexColumn.")
            FROM   $sTable
        ";
        $rResultTotal = $connection->query($sQuery);
        $aResultTotal = $rResultTotal->fetch();
        $iTotal = $aResultTotal[0];
         
         
        /*
         * Output
         */
        $output = array(
            "sEcho" => intval($_GET['sEcho']),
            "iTotalRecords" => $iTotal,
            "iTotalDisplayRecords" => $iFilteredTotal,
            "aaData" => array()
        );
      
        while ( $aRow =  $rResult->fetch())
        {
            $row = array();
            for ( $i=0 ; $i<count($aColumns) ; $i++ )
            { 
                 if (!empty($aColumns[$i]) )
                {
                    /* General output */
                    $row[] = $aRow[ $aColumns[$i] ];
                }
            }
            $output['aaData'][] = $row;
        }
         
        echo json_encode($output);
    
    
  6. i am now getting undefined index error when trying to run this c. company_name otherwise the json is good

    <?php
    
         //connect to database
         include '../../Model/DBAdapter.php';
    
    
        $aColumns = array( 'RMA_Number', 'Person_Calling', 'c.Company_Name', 'Unit_Serial_Number', 'CONCAT(e.Employee_First_Name, " ", e.Employee_Last_Name)',
                            'Call_Date','Received_Date','RMA_Status','Reason_For_Return','Notes','New_Install',
                            'New_Unit_Serial_Number', 'Terminal_ID','Account_Number','Account_Name');
         
        /* Indexed column (used for fast and accurate table cardinality) */
        $sIndexColumn = "RMA_Number";
         
        /* DB table to use */
        $sTable = "RMA";
        
        //Join to use
        $sJoin = 'JOIN Companies c ON RMA.Company_ID  = c.Company_ID';
        $sJoin .= ' JOIN Employees e ON RMA.Employee_ID  = e.Employee_ID';
         
    
         
        /*
         * Paging
         */
        $sLimit = "";
        if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
        {
            $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ".
                intval( $_GET['iDisplayLength'] );
        }
         
         
        /*
         * Ordering
         */
        $sOrder = "";
        if ( isset( $_GET['iSortCol_0'] ) )
        {
            $sOrder = "ORDER BY  ";
            for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
            {
                if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
                {
                    $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
                        ".($_GET['sSortDir_'.$i]==='asc' ? 'asc' : 'desc') .", ";
                }
            }
             
            $sOrder = substr_replace( $sOrder, "", -2 );
            if ( $sOrder == "ORDER BY" )
            {
                $sOrder = "";
            }
        }
         
         
        /*
         * Filtering
         * NOTE this does not match the built-in DataTables filtering which does it
         * word by word on any field. It's possible to do here, but concerned about efficiency
         * on very large tables, and MySQL's regex functionality is very limited
         */
        $sWhere = "";
        if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
        {
            $sWhere = "WHERE (";
            for ( $i=0 ; $i<count($aColumns) ; $i++ )
            {
                if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" )
                {
                    $sWhere .= $aColumns[$i]." LIKE '%".  htmlspecialchars( $_GET['sSearch'] )."%' OR ";
                }
            }
            $sWhere = substr_replace( $sWhere, "", -3 );
            $sWhere .= ')';
        }
         
        /* Individual column filtering */
        for ( $i=0 ; $i<count($aColumns) ; $i++ )
        {
            if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
            {
                if ( $sWhere == "" )
                {
                    $sWhere = "WHERE ";
                }
                else
                {
                    $sWhere .= " AND ";
                }
                $sWhere .= $aColumns[$i]." LIKE '%".  htmlspecialchars($_GET['sSearch_'.$i])."%' ";
            }
        }
         
         
        /*
         * SQL queries
         * Get data to display
         */
        $sQuery = "
            SELECT SQL_CALC_FOUND_ROWS " . str_replace(" , ", " ", implode(", ", $aColumns)) . "
            FROM   $sTable
            $sJoin
            $sWhere
            $sOrder
            $sLimit
        ";
    try {
        $rResult = $connection->query($sQuery);
    } catch (PDOException $e) {
        $error = 'Error getting data: ' . $e->getMessage();
        echo $error;
        exit();
    }
    
    /* Data set length after filtering */
        $sQuery = "
            SELECT FOUND_ROWS()
        ";
        try{
        $rResultFilterTotal = $connection->query($sQuery);
        $aResultFilterTotal = $rResultFilterTotal->fetch();
        $iFilteredTotal = $aResultFilterTotal[0];
        }catch (PDOException $e) {
        $error = 'Error getting found rows: ' . $e->getMessage();
        echo $error;
        exit();
    }
        /* Total data set length */
        $sQuery = "
            SELECT COUNT(".$sIndexColumn.")
            FROM   $sTable
        ";
        $rResultTotal = $connection->query($sQuery);
        $aResultTotal = $rResultTotal->fetch();
        $iTotal = $aResultTotal[0];
         
         
        /*
         * Output
         */
        $output = array(
            "sEcho" => intval($_GET['sEcho']),
            "iTotalRecords" => $iTotal,
            "iTotalDisplayRecords" => $iFilteredTotal,
            "aaData" => array()
        );
         
        while ( $aRow =  $rResult->fetch())
        {
            $row = array();
            for ( $i=0 ; $i<count($aColumns) ; $i++ )
            { 
                 if ( $aColumns[$i] != ' ' )
                {
                    /* General output */
                    $row[] = $aRow[ $aColumns[$i] ];
                }
            }
            $output['aaData'][] = $row;
        }
         
        echo json_encode( $output );
    ?>
    
  7. This is what i came up with for the code but i get a json error when trying to run it

    <?php
    
         //connect to database
         include 'Model/DBAdapter.php';
    
    
        $aColumns = array( 'RMA_Number', 'Person_Calling', 'c.Company_Name', 'Unit_Serial_Number', 'Employee_Name',
                            'Call_Date','Received_Date','RMA_Status','Reason_For_Return','Notes','New_Install',
                            'New_Unit_Serial_Number', 'Terminal_ID','Account_Number','Account_Name');
         
        /* Indexed column (used for fast and accurate table cardinality) */
        $sIndexColumn = "RMA_Number";
         
        /* DB table to use */
        $sTable = "RMA";
        
        //Join to use
        $sJoin = 'JOIN Companies c ON RMA.Company_ID  = Companies.Company_ID';
        $sJoin .= ' JOIN Employees e ON RMA.Employee_ID  = Employees.Employee_ID';
         
    
         
        /*
         * Paging
         */
        $sLimit = "";
        if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
        {
            $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ".
                intval( $_GET['iDisplayLength'] );
        }
         
         
        /*
         * Ordering
         */
        $sOrder = "";
        if ( isset( $_GET['iSortCol_0'] ) )
        {
            $sOrder = "ORDER BY  ";
            for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
            {
                if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
                {
                    $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
                        ".($_GET['sSortDir_'.$i]==='asc' ? 'asc' : 'desc') .", ";
                }
            }
             
            $sOrder = substr_replace( $sOrder, "", -2 );
            if ( $sOrder == "ORDER BY" )
            {
                $sOrder = "";
            }
        }
         
         
        /*
         * Filtering
         * NOTE this does not match the built-in DataTables filtering which does it
         * word by word on any field. It's possible to do here, but concerned about efficiency
         * on very large tables, and MySQL's regex functionality is very limited
         */
        $sWhere = "";
        if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
        {
            $sWhere = "WHERE (";
            for ( $i=0 ; $i<count($aColumns) ; $i++ )
            {
                if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" )
                {
                    $sWhere .= $aColumns[$i]." LIKE '%".  htmlspecialchars( $_GET['sSearch'] )."%' OR ";
                }
            }
            $sWhere = substr_replace( $sWhere, "", -3 );
            $sWhere .= ')';
        }
         
        /* Individual column filtering */
        for ( $i=0 ; $i<count($aColumns) ; $i++ )
        {
            if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
            {
                if ( $sWhere == "" )
                {
                    $sWhere = "WHERE ";
                }
                else
                {
                    $sWhere .= " AND ";
                }
                $sWhere .= $aColumns[$i]." LIKE '%".  htmlspecialchars($_GET['sSearch_'.$i])."%' ";
            }
        }
         
         
        /*
         * SQL queries
         * Get data to display
         */
        $sQuery = "
            SELECT SQL_CALC_FOUND_ROWS " . str_replace(" , ", " ", implode(", ", $aColumns)) . "
            FROM   $sTable
            $sJoin
            $sWhere
            $sOrder
            $sLimit
        ";
    try {
        $rResult = $connection->query($sQuery);
    } catch (PDOException $e) {
        $error = 'Error getting data: ' . $e->getMessage();
        echo $error;
        exit();
    }
    
    /* Data set length after filtering */
        $sQuery = "
            SELECT FOUND_ROWS()
        ";
        try{
        $rResultFilterTotal = $connection->query($sQuery);
        $aResultFilterTotal = $rResultFilterTotal->fetchAll();
        $iFilteredTotal = $aResultFilterTotal[0];
        }catch (PDOException $e) {
        $error = 'Error getting found rows: ' . $e->getMessage();
        echo $error;
        exit();
    }
        /* Total data set length */
        $sQuery = "
            SELECT COUNT(".$sIndexColumn.")
            FROM   $sTable
        ";
        $rResultTotal = $connection->query($sQuery);
        $aResultTotal = $rResultTotal->fetchAll();
        $iTotal = $aResultTotal[0];
         
         
        /*
         * Output
         */
        $output = array(
            "sEcho" => intval($_GET['sEcho']),
            "iTotalRecords" => $iTotal,
            "iTotalDisplayRecords" => $iFilteredTotal,
            "aaData" => array()
        );
         
        while ( $aRow =  $rResult->fetchAll())
        {
            $row = array();
            for ( $i=0 ; $i<count($aColumns) ; $i++ )
            { 
                 if ( $aColumns[$i] != ' ' )
                {
                    /* General output */
                    $row[] = $aRow[ $aColumns[$i] ];
                }
            }
            $output['aaData'][] = $row;
        }
         
        echo json_encode( $output );
    ?>
    
  8. Hello i was wondering if anyone could help convert my datatable over to the server side datatables. I attached my full code for the datatable

    php
    //connect to database
    include 'Model/DBAdapter.php';
    //create sql statement
    $sql = "SELECT RMA_Number, Person_Calling, Company_Name, Unit_Serial_Number,
        CONCAT(Employee_First_Name,' ',Employee_Last_Name) AS Employee_Name,
        Call_Date,Received_Date,RMA_Status, Reason_For_Return, Notes, New_Install,
        New_Unit_Serial_Number, Terminal_ID, Account_Number, Account_Name FROM RMA
    			JOIN Companies ON RMA.Company_ID  = Companies.Company_ID
    			JOIN Employees ON RMA.Employee_ID  = Employees.Employee_ID";
    //Retrieve data
    $result = $connection->query($sql);
    //process results
    if ($result) {
        //loop through data
        while ($view = $result->fetch()) {
            $views[] = $view;
        }
        //display
        include 'View/View.html.php';
    } else {
        //error message
        $output = "No RMA found in database.";
        include 'View/Template.html.php';
    }
    
    
    <body>
            <div id="wrapper">
                <h1 id="tableTitle">RMA's Submitted</h1>
                <table id="table">
                    <thead>
                        <tr>
                            <th>RMA Number</th>
                            <th>Person Calling</th>
                            <th>Company ID</th>
                            <th>ISN</th>
                            <th>Employee</th>
                            <th>Call Date</th>	
                            <th>Received Date</th>
                            <th>RMA Status</th>	
                            <th>Reason for Return</th>
                            <th>Notes</th>
                            <th>New Install</th>
                            <th>New Serial Number</th>
                            <th>Terminal ID</th>
                            <th>Account Number</th>
                            <th>Account Name</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($views as $view): ?>
                            <tr>
                                <td><?php echo $view['RMA_Number']; ?></td>
                                <td><?php echo $view['Person_Calling']; ?></td>
                                <td><?php echo $view['Company_Name']; ?></td>
                                <td><?php echo $view['Unit_Serial_Number']; ?></td>
                                <td><?php echo $view['Employee_Name']; ?></td>
                                <td><?php echo $view['Call_Date']; ?></td>
                                <td><?php echo $view['Received_Date']; ?></td>
                                <td><?php echo $view['RMA_Status']; ?></td>
                                <td><?php echo $view['Reason_For_Return']; ?></td>
                                <td><?php echo $view['Notes']; ?></td>
                                <td><?php echo $view['New_Install']; ?></td>
                                <td><?php echo $view['New_Unit_Serial_Number']; ?></td>
                                <td><?php echo $view['Terminal_ID']; ?></td>
                                <td><?php echo $view['Account_Number']; ?></td>
                                <td><?php echo $view['Account_Name']; ?></td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </body>
    
    

    here is an example of the server-side with datatables  but im using pdo.

     

    http://www.datatables.net/release-datatables/examples/data_sources/server_side.html

    View.html.zip

  9. I achieved what I wanted by changing

    <?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 = strtoupper(htmlspecialchars($_POST['scanISN'], ENT_QUOTES, 'UTF-8'));
    		$rmaNumber = htmlspecialchars($_POST['rmaNumber'], ENT_QUOTES, 'UTF-8');
    		
    		//create sql query to check if unit exists
    		$sql1 = $connection->prepare("SELECT Received_Date,RMA_Status FROM rma WHERE Unit_Serial_Number = '$scanISN' AND RMA_Number = '$rmaNumber'");
    		//run sql query
    		$sql1->execute();
    		
    		//if the query executes do the update statement
    		if ($sql1->rowCount() > 0){
    		//create sql query
    		$sql = $connection->prepare("UPDATE RMA SET Received_Date = '$receiveDate', RMA_Status = '$rmaStatus' 
    				WHERE Unit_Serial_Number = '$scanISN' AND RMA_Number = '$rmaNumber' AND RMA_Status != '$rmaStatus'");
    		
    		//if the update statement does not execute
    		if ($sql->rowCount() <= 0){
    			$output = "RMA updated failed.";
    		}
    		else {
    			$output = "RMA information updated.";
    		}
    }
    else {
    	$output = "RMA does not exist please contact support";
    	}
    			
    		include('View/ScanOutput.html.php');
    		
    }
    

     the last if and adding another AND to the last sql statement! Thanks everyone for your help I really appreciate it! I look forward to learning more from you :)

  10. I think this works for that but the only other question is when one record is updated already it will say it doesn't exist. im doing something wrong here

    <?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 = strtoupper(htmlspecialchars($_POST['scanISN'], ENT_QUOTES, 'UTF-8'));
    		$rmaNumber = htmlspecialchars($_POST['rmaNumber'], ENT_QUOTES, 'UTF-8');
    		
    		//create sql query to check if unit exists
    		$sql1 = $connection->prepare("SELECT Received_Date,RMA_Status FROM rma WHERE Unit_Serial_Number = '$scanISN' AND RMA_Number = '$rmaNumber'");
    		//run sql query
    		$sql1->execute();
    		$affected1 = $sql1->rowCount();
    		
    		//create sql query
    		$sql = $connection->prepare("UPDATE RMA SET Received_Date = '$receiveDate', RMA_Status = '$rmaStatus' 
    				WHERE Unit_Serial_Number = '$scanISN' AND RMA_Number = '$rmaNumber'");
    		//run sql query
    		$sql->execute();
    		$affected = $sql->rowCount();		
    		
    		if($affected <= 0 || $affected1 <= 0){
        	 //error
        	 $output = "RMA does not exist please contact support";
        	
    		} else {
       		  //success
       		 $output = "RMA information updated.";
    		
    		}include('View/ScanOutput.html.php');
    }
    
  11. This is what I have it seems to work but when I try to update the same twice it will say it doesn't exist. Am I doing this right?

    <?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 = strtoupper(htmlspecialchars($_POST['scanISN'], ENT_QUOTES, 'UTF-8'));
    		$rmaNumber = htmlspecialchars($_POST['rmaNumber'], ENT_QUOTES, 'UTF-8');
    
    		
    		//create sql query
    		$sql = $connection->prepare("UPDATE RMA SET Received_Date = '$receiveDate', RMA_Status = '$rmaStatus' 
    				WHERE Unit_Serial_Number = '$scanISN' AND RMA_Number = '$rmaNumber'");
    		//run sql query
    		$sql->execute();
    		$affected = $sql->rowCount();
    				
    		if($affected <= 0){
        	     	 $output = "RMA does not exist please contact support";
        	
    		} else {
       		 $output = "RMA information updated.";
    		
    		}include('View/ScanOutput.html.php');
    }
    
  12. <?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'");
    		//run sql query
    		$result = $connection->query($sql);
    		
    		//create sql query
    		$sql2 = ("SELECT Received_Date, RMA_Status FROM RMA WHERE Unit_Serial_Number = '$scanISN' AND RMA_Number = '$rmaNumber'"); 
    		
    		//run sql query
    		$result2 = $connection->query($sql2);
    		
    		//loop through data
    		while ($row = $result2->fetch()){
    		
    		$check1 = $row['Received_Date'];
    		$check2 = $row['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');
    		}
    }}
    

    Looks like my copy didn't get all the code the first time

  13. 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');
    }
    
    
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.