Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Update/Delete #507

Closed
razarahil opened this issue Apr 17, 2013 · 3 comments
Closed

Problem with Update/Delete #507

razarahil opened this issue Apr 17, 2013 · 3 comments

Comments

@razarahil
Copy link

Hello
I'm using jTable with PHP & MySQL. I used your script and slightly modified it. It's working fine here in localhost. But when I try same script on main server. Update/Delete is not working. Though I can add an entry.

My code:

urlslug($categoryslugraw); //Insert record into database $result = mysql_query("INSERT INTO category(categoryname, categoryslug) VALUES('$categoryname', '$categoryslug');"); //Get last inserted record (to return to jTable) $result = mysql_query("SELECT * FROM category WHERE id = LAST_INSERT_ID();"); $row = mysql_fetch_array($result); //Return result to jTable $jTableResult = array(); $jTableResult['Result'] = "OK"; $jTableResult['Record'] = $row; print json_encode($jTableResult); } //Updating a record (updateAction) else if($_GET["action"] == "update") { $updateid=mysql_real_escape_string($_POST["id"]); $categoryname=mysql_real_escape_string($_POST['categoryname']); $categoryname=ucwords($categoryname); $categoryslugraw=mysql_real_escape_string($_POST['categoryslug']); $categoryslug=$handler->urlslug($categoryslugraw); //Update record in database $result = mysql_query("UPDATE category SET categoryname = '$categoryname', categoryslug = '$categoryslug' WHERE id ='$updateid';"); //Return result to jTable $jTableResult = array(); $jTableResult['Result'] = "OK"; print json_encode($jTableResult); } //Deleting a record (deleteAction) else if($_GET["action"] == "delete") { $deleteid=mysql_real_escape_string($_POST["id"]); //Delete from database $result = mysql_query("DELETE FROM category WHERE id = '$deleteid';"); //Return result to jTable $jTableResult = array(); $jTableResult['Result'] = "OK"; print json_encode($jTableResult); } //Close database connection ``` // mysql_close($con); } catch(Exception $ex) { //Return error message $jTableResult = array(); $jTableResult['Result'] = "ERROR"; $jTableResult['Message'] = $ex->getMessage(); print json_encode($jTableResult); } ?>
@rainulf
Copy link

rainulf commented Apr 17, 2013

Was it working before you slightly modified it? Maybe the issue on your side and not with jTable?

@nubuntu
Copy link

nubuntu commented Apr 19, 2013

i use chrome to inspect element
then go to network => XHR
then copy last ajax request that occured error as curl
then paste ini browser the url and request data
but before i change all $_POST request to $_REQUEST,
and echo all query, and print_r an array
one by one till i know where error is

my advice is
good to know https://github.com/nubuntu/jtable if you use php :)

@razarahil
Copy link
Author

I found the problem, nothing wrong with the script. Actually i didn't give the db user permission to update/delete.
Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants