Author Topic: Data does not get saved to MySQL-DB  (Read 5258 times)

jaguar23

  • Newbie
  • *
  • Posts: 5
    • View Profile
Data does not get saved to MySQL-DB
« on: October 04, 2017, 11:44:25 pm »
Hi,

i want to build an inline editable grid with filters and frozen columns, is the connection of these features possible?

I started with the 'Auto Save' example and my MySQL table is showing nicely, but any edits I do are gone after page reload.
I don't get any errors in the web dev console and none in the apache log. How do you debug this kind of technology? (I am not a frontend dev obviously)

Regards,
J.
« Last Edit: October 05, 2017, 12:09:48 am by jaguar23 »

jaguar23

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Data does not get saved to MySQL-DB
« Reply #1 on: October 05, 2017, 02:50:14 am »
I got filtering and freezeCol to work too.
As far as I understand the PHP-code the addList, updateList and deleteList function do not write into the MySQL-table, which means they have to be implemented by hand?
« Last Edit: October 05, 2017, 03:10:33 am by jaguar23 »

jaguar23

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Data does not get saved to MySQL-DB
« Reply #2 on: October 05, 2017, 07:23:23 pm »
So far I came up with this code:

Code: [Select]
function deleteList($deleteList){
    foreach ($deleteList as $row)
    {
$primaryKey = $row["uid"];
$sql = "DELETE FROM MYTABLE WHERE uid='".$primaryKey."'";
$dsn = 'mysql:host='.DB_HOSTNAME.';dbname='.DB_NAME;
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
$dbh = new PDO($dsn, DB_USERNAME, DB_PASSWORD, $options);
$stmt = $dbh->prepare($sql);
$stmt->execute();
    }
    return $deleteList;
}

This does not work, the MySQL command does not even get triggered.
Can anybody explain to me, what I am getting wrong?
« Last Edit: October 05, 2017, 08:29:54 pm by jaguar23 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Data does not get saved to MySQL-DB
« Reply #3 on: October 05, 2017, 08:51:25 pm »
Have you added this part. And were you able to debug your code. The deleteList function is called only when there are deleted records in the grid.

Code: [Select]
if( isset($_GET["pq_batch"]))   
{
    session_start();
    $dlist = $_POST['list'];
   
    if(isset($dlist["updateList"])){
        $dlist["updateList"] = updateList($dlist["updateList"]);
    }
    if(isset($dlist["addList"])){
        $dlist["addList"] = addList($dlist["addList"]);
    }
    if(isset($dlist["deleteList"])){
        $dlist["deleteList"] = deleteList($dlist["deleteList"]);
    }
   
    echo json_encode($dlist);


jaguar23

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Data does not get saved to MySQL-DB
« Reply #4 on: October 05, 2017, 09:07:15 pm »
Thank you very much for you answer!

Yes, that code is in there too, I took the Auto Save example code as template.
I am still not sure how to debug it best, I am watching the web dev console and the apache and mysql logs for now; since my MySQL code does not even get triggered, I assume that whole function does not get called, which means it fails at the code you posted or before...

jaguar23

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Data does not get saved to MySQL-DB
« Reply #5 on: October 06, 2017, 01:08:34 am »

linuxhong

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 5
  • paramquery pro beginner
    • View Profile
Re: Data does not get saved to MySQL-DB
« Reply #6 on: December 29, 2017, 04:52:23 pm »
Me too

I have a same problem... and I am a pro buyer

Please help me....

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Data does not get saved to MySQL-DB
« Reply #7 on: December 29, 2017, 05:26:05 pm »
It's expected that you have working knowledge of javascript/ jquery and php and bit familiar with debugging your code.

Please follow this example:

https://paramquery.com/pro/demos/editing_instant

In this example, lists are saved in session. You might need to change the code to save it in your database.

If you face issues, please mention all details and share your code / plnkr

https://plnkr.co/edit/zo6TdOvweAFvWM5JLasV?p=preview