tags:

views:

51

answers:

5

i want to delete some data use:

    $dbc=mysql_connect(_SRV,_ACCID,_PWD) or die(_ERROR15.": ".mysql_error());
    $db=mysql_select_db("qdbase",$dbc) or die(_ERROR17.": ".mysql_error());

    switch(postVar('action')) {
              case 'changedata': 
 changedata(postVar('id'),postVar('chlotno'),postVar('chrange'),postVar('chS'),postVar('chA'),postVar('chB'),postVar('chC'),postVar('chstatus'));
                break;
        case 'deldata':
                deldata(postVar('delid'));
                break;
              }

    function changedata($id,$chlotno,$chrange,$chS,$chA,$chB,$chC,$chstatus){
        $ID = mysql_real_escape_string($id);
        $Lot_no = mysql_real_escape_string($chlotno);
        $Range = mysql_real_escape_string($chrange);
        $S = mysql_real_escape_string($chS);
        $A = mysql_real_escape_string($chA);
        $B = mysql_real_escape_string($chB);
        $C = mysql_real_escape_string($chC);
        $Status = mysql_real_escape_string($chstatus);
        $Lot_no=strtoupper($Lot_no);
        $Range=strtoupper($Range);

        $sql = "UPDATE inspection_report SET Lot_no = '".$Lot_no."', Range_sampling = '".$Range."', S = '".$S."', ";
        $sql.= "A = '".$A."', B = '".$B."', C = '".$C."', Status = '".$Status."' ";
        $sql.= "WHERE id = ".$ID;

echo $sql;
$result=mysql_query($sql) or die(_ERROR26.": ".mysql_error());
//echo $result;
mysql_close($dbc);
}
function deldata($id){
        $ID = mysql_real_escape_string($id);
        $sql = "DELETE FROM inspection_report WHERE id = '".$ID."'";

echo $sql;
$result=mysql_query($sql) or die(_ERROR26.": ".mysql_error());
//echo $result;
mysql_close($dbc);
}

I have not found any error message in this query and show "200,OK". But the data still exist (not deleted). why its happen? is there something wrong in my query?

echo $sql:DELETE FROM inspection_report WHERE id = ''
A: 

In PHP $id and $ID are two different variables.

Mchl
He is using `$ID` in his sql query which is correct.
Sarfraz
`$ID = mysql_real_escape_string($id);`
Alexander.Plutov
True that. Was too quick this time :)
Mchl
A: 

make sure that the $id variable is same case throughout, $id != $ID

Stephan Grobler
so what is the better way for me?
klox
`$ID = mysql_real_escape_string($id);`
Alexander.Plutov
i would make $safeId = mysql_real_escape_string($id);$sql = "DELETE FROM inspection_report WHERE id = '".$safeId."'"; Just to make sure there is no confusion as to the variable to use
Stephan Grobler
i have been change like your opinion, but i still cant delete data.
klox
what is postVar? how do you get that values, because im thinking it does not get the value passed... and looking at your code again, is see that changedata gets postVar(id) and deldata gets postVar(delid), should they not be the same?
Stephan Grobler
A: 

postVar is not a variable. Try to use $postVar. If your postVar is a function, give us code of this function. I don't see a end of the switch function.

Alexander.Plutov
sorry i forget post the end of switch, but it still not work but for edit it works.
klox
A: 

Based on the echo $sql it looks like postVar('delid') is returning null.

You should check your code and see if 'delid' is what you're actually passing to your script or if there is some other reason why it isn't set.

How is 'delid' set?

kskjon
A: 

huft sorry...i have made a stupid mistake, this is my answer:

$('#balupdate').click(function() {
          if ($("#editbaldata").valid()){
                     var params = $('#editbaldata').serialize();
                     $.ajax({
                             async  : false,
                             cache  : false,
                             data   : params,
                             success: function(res) {

i miss the .serialize()

klox