Welcome Guest, Not a member yet? Register   Sign In
Flexigrid - delete.php is not working - help needed!!!
#1

[eluser]jikowhitewolf[/eluser]
I have been trying to get delete.php to work from http://sanderkorvemaker.nl/test/flexigrid/ again , but somehow it is not deleting from my table, even when i have enabled the sql runSQL to do the delete action.

I read someone has the same problem at this post. http://ellislab.com/forums/viewthread/75326/P270/
post#280, that all they did is remove the trailing comma (,) but where is the trailing comma (,)?

Code:
<?
error_reporting(0);
function runSQL($rsql) {
    $hostname = "localhost";
    $username = "root";
    $password = "";
    $dbname   = "tutorial";
    $connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
    $db = mysql_select_db($dbname);
    $result = mysql_query($rsql) or die ('test');
    return $result;
    mysql_close($connect);
}

$items = rtrim($_POST['items'],",");
$sql = "DELETE FROM 'service_table' WHERE 'id' IN ($items)";

$total = count(explode(",",$items));
$result = runSQL($sql);
$total = mysql_affected_rows();
/// Line 18/19 commented for demo purposes. The MySQL query is not executed in this case. When line 18 and 19 are uncommented, the MySQL query will be executed.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
$json = "";
$json .= "{\n";
$json .= "query: '".$sql."',\n";
$json .= "total: $total,\n";
$json .= "}\n";
echo $json;
?>
#2

[eluser]cahva[/eluser]
Code:
$json .= "total: $total,\n";
..there. After $total
#3

[eluser]jikowhitewolf[/eluser]
thank you so much, it works.

but I also notice another thing.

Code:
$sql = "DELETE FROM `service_table` WHERE `id` IN ($items)";
// WORKS

if I change to ` to ':
Code:
$sql = "DELETE FROM 'service_table' WHERE 'id' IN ($items)";
// DO NOT WORK

Now I wish to make a update.php, from this delete.php
Code:
$sql = "UPDATE service_table SET granted=`1` WHERE `id` IN ($items)";

but it just does not work, is it because of the json? Or is there anything wrong with my UPDATE statement?

In my update php, I want to update "granted" to true.
#4

[eluser]jikowhitewolf[/eluser]
ok, my update.php works now.
But the json is not working for the update.php. I am not familiar with json, can anyone help me on the json below? It is the same example from delete.php, I only change the $sql for updating the database.


Code:
$items = rtrim($_POST['items'],",");
$sql = "UPDATE service_table SET granted='1' WHERE id IN ($items)";

$total = count(explode(",",$items));
$result = runSQL($sql);
$total = mysql_affected_rows();


header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");

$json = "";
$json .= "{\n";
$json .= "query: '".$sql."',\n";
$json .= "total: $total\n";
$json .= "}\n";
echo $json;
?>


I do not receive the json success alert box such as this.
query: 'UPDATE service_table SET granted='1' WHERE id IN 1',
total: 3,

So that is why I am guessing it is the json. is it?
#5

[eluser]jikowhitewolf[/eluser]
first method, I try adding the error in ajax, and it prints out ParserError
Code:
error: function(XMLHttpRequest, textStatus, errorThrown)
{
     alert(textStatus + " | " + errorThrown);     // throw ParserError
}



my second method, I use json_encode but it throw $sql and $total as undefined.

Code:
$json = "";
$json .= "{\n";
$json .= "query: '".$sql."',\n";
$json .= "total: $total\n";
$json .= "}\n";
echo json_encode($json);

anyone has any idea of this?
#6

[eluser]cahva[/eluser]
Do you use Firebug? If not, please do Smile With that you can see what kind of response you get from the server and see that the response is valid.
#7

[eluser]jikowhitewolf[/eluser]
Oh, it needs FireFox and Firebug. Thanks, I will check it out.
#8

[eluser]phpserver[/eluser]
I suggest jqgrid.You can see its power here and the codeigniter implementation here.
#9

[eluser]jikowhitewolf[/eluser]
jqgrid looks really impressive, too bad it is quite expensive.
#10

[eluser]phpserver[/eluser]
That's what i thought the first time but i soon learn't that you could actually use it and buy the license when you need it,its actually based on jquery which is free.




Theme © iAndrew 2016 - Forum software by © MyBB