feedz87 0 Newbie Poster
  • I have the problem where my update is not not working.Anybody can help me...

FORM

<code>
<?php 

session_start();

include ("../entity/login_class.php");
include ("../entity/admin_class.php");
include ("../entity/customer_class.php");

  $Customers = new Customer();
  $id = $Customers-> getCargoID();
  $Customers ->getCargo($_GET['id']);

  $id = $Customers->getCargoID();
  $cargoCode = $Customers->getCargoCode();
  $cargoDesc = $Customers->getCargoDesc();
?>

<form method="post" name="updateCustomer" id="updateCustomer" action="../controller/customer_control.php" method="post">

<table width="99%" height="100" border="0" align="center" bgcolor="#FFFFCC">
  <tr>
    <td width="53%" height="32">Cargo Code</td>
    <td width="47%">Cargo Description</td>
  </tr>
  <tr>  
    <td height="27"><input name="cargoCode" type="text" id="cargoCode"/></td>
    <td><input name="cargoDesc" type="text" id="cargoDesc"/></td>
  </tr>
  <tr>
    <td height="33"><input name="submitInfo" type="button" id="submitInfo" value="Add Cargo" /></td>
    <td>&nbsp;</td>
  </tr>
</table>
<table id="test" width="99%" height="29" border="1" align="center" bordercolor="#FFFF99" bordercolordark="#FFFF99">
<tbody>
    <tr>
        <td width="145" height="23"><input name="stud" type="hidden" id="stud" readonly /></td>
        <td width="145"><input name="student" type="hidden" id="student" readonly /></td>
    </tr>
</tbody>
    <tr>
      <td width="182" height="71"><p align="right" class="style7">
        <input name="UpdateCustomer" type="submit" value="Submit" id="UpdateCustomer" />
      </p></td>
      <td width="161" height="71"><p align="Left" class="style7">
        <input type="reset" name="Submit2" value="Reset" />
      </p></td><input name="id" type="hidden" id="id" value="<?php echo $id; ?>"></td>
    </tr>
</table>

<script type="text/javascript" src="jquery.js"></script>
<script language="javascript">
$(document).ready(function(){

$("#submitInfo").click(function() {
deleteAjax();
});

function deleteAjax()
{
var controllerpath = "../entity/customer_class.php";
var cargoCode = $("#cargoCode").val();
var cargoDesc = $("#cargoDesc").val();
$("#cargoCode").val('');
$("#cargoDesc").val('');

var a="<?php echo $cargoCode; ?>";
var b="<?php echo $cargoDesc; ?>";

$('#test > tbody:last').append('<tr><td><input type="text" name="mapih[]" value='+a+'/>'+a+'</td><td><input type="text" name="mapiha[]" value='+b+'/>'+b+'</td></tr>');

$.ajax(
{
    type: "POST",
    async : false,
    url: controllerpath,
    dataType: 'json',
    data : 
    {
        cargoCode : cargoCode,
        cargoDesc : cargoDesc,
    },
    success : function(data) 
    {


    },
    error : function(XMLHttpRequest, textStatus, errorThrown) 
    {
        alert(XMLHttpRequest + " : " + textStatus + " : " + errorThrown);
    }
    }); 
}

});
</script>
<form>
</code>

CLASS

<code>
    public function updateCustomerFunc($id,$mapih,$mapiha)
    {
        $mapih = $_POST['mapih'];
        $mapiha = $_POST['mapiha'];
        foreach($mapih as $key=>$value) 
        {   
            $s=$mapiha[$key];
            $sql2 = "UPDATE cargo SET cargoCode='$value', cargoDesc='$s' WHERE id='$id'";
            $result = mysql_query($sql2);
        }
        return $result;
    }
</code>

CONTROLLER

<code>
if(isset ($_POST['UpdateCustomer']))
{   
    echo $mapih = $_POST['mapih'];
    echo $mapiha=$_POST['mapiha'];

    foreach($mapih as $key=>$value)
    {
        echo $s=$mapiha[$key];
    }
    $Customers = new Customer();
    $updateCustomer = $Customers->updateCustomerFunc($id,$mapih,$mapiha);

    $id = trim(addslashes($_POST['id']));

        $Customers = new Customer();
        $updateCustomer = $Customers->updateCustomerFunc($id,$mapih,$mapiha);

        if($updateCustomer == true)
        {
            echo "<script language='JavaScript'>alert('Update Success.'); window.location ='../boundary/customerList.php';</script>";
        }
        else
        {
            echo "<script language='JavaScript'>alert('Fail to update.Report error.'); window.location ='../boundary/customerList.php';</script>";    
        }  
}
</code>