Author Topic: PHP add, update, delete  (Read 22617 times)

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
PHP add, update, delete
« on: February 03, 2014, 06:10:55 pm »
Hello again,

I'm looking at your "Batch editing" example.
Could you please share the PHP code for add, update, delete?
It seems you are using different files for the ajax calls.

Thanks in advance for your support!

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5290
    • View Profile
Re: PHP add, update, delete
« Reply #1 on: February 03, 2014, 06:56:33 pm »
[ Only Pro members may read this post. ]
« Last Edit: February 03, 2014, 06:59:43 pm by paramquery »

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: PHP add, update, delete
« Reply #2 on: February 04, 2014, 12:11:17 am »
That's easier to understand thanks.

I still can't figure out how the data for new rows data is being sent to PHP.

For example, when adding the last row of the attached image, I can see the #consola has logged:

Code: [Select]
[{"orcamento":"10","atual":"20","desvio":"","data":"2015-01-01","nome_conta":"BBB","nome_categoria":"abc","nome_entidade":"def"}] which is the data I want to insert into the table.

But in PHP, nothing is being posted:

Code: [Select]
if( isset($_POST["addList"]))           
{
$addList = json_decode($_POST["addList"], true);
var_dump ($addList);
echo "test";
exit();
}

This is outputing
Quote
NULLtest

How do I get the data in PHP so I can build a query and insert it into mySQL?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5290
    • View Profile
Re: PHP add, update, delete
« Reply #3 on: February 04, 2014, 12:46:00 am »
[ Only Pro members may read this post. ]

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: PHP add, update, delete
« Reply #4 on: February 04, 2014, 12:47:42 am »
I did, here's the code for the ajax call:

Code: [Select]
//send to server
            if (addList.length) {
                $.ajax($.extend({}, ajaxObj, {
                    data: { "addList": JSON.stringify(addList) },
                    success: function (rows) {
                        $grid.pqGrid("commit", { type: 'add', rows: rows });
                       
                    },
                    complete: function () {
                        $grid.pqGrid("hideLoading");
                        $grid.pqGrid("rollback", { type: 'add' });
                        $('#consola').text(JSON.stringify(addList));
                    }
                }));

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5290
    • View Profile
Re: PHP add, update, delete
« Reply #5 on: February 04, 2014, 01:33:10 am »
[ Only Pro members may read this post. ]
« Last Edit: February 04, 2014, 07:52:11 am by paramquery »

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: PHP add, update, delete
« Reply #6 on: February 04, 2014, 03:19:29 pm »
You may see the whole code in attachment.

ajaxObj is defined before the ajax call.


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5290
    • View Profile
Re: PHP add, update, delete
« Reply #7 on: February 04, 2014, 05:14:53 pm »
[ Only Pro members may read this post. ]

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: PHP add, update, delete
« Reply #8 on: February 04, 2014, 05:17:20 pm »
I get
Code: [Select]
NULL
I was expecting to get the changed data, as displayed on
Code: [Select]
"#consola".

So the data isn't being sent to PHP and therefore, I'm not able to build the INSERT query to insert it into mySQL.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5290
    • View Profile
Re: PHP add, update, delete
« Reply #9 on: February 04, 2014, 05:33:24 pm »
[ Only Pro members may read this post. ]

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: PHP add, update, delete
« Reply #10 on: February 04, 2014, 05:39:27 pm »
Same result: nothing is sent to the PHP script.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5290
    • View Profile
Re: PHP add, update, delete
« Reply #11 on: February 04, 2014, 07:12:28 pm »
[ Only Pro members may read this post. ]
« Last Edit: February 04, 2014, 07:15:29 pm by paramquery »

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: PHP add, update, delete
« Reply #12 on: February 04, 2014, 07:28:31 pm »
Here you go:

Code: [Select]
Request URL:http://www.portal-gestao.com/budget/incluir/json4.php
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4,pt-BR;q=0.2
Connection:keep-alive
Content-Length:113
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:visitas=5; 0cf3259c57baa4009afba854fca3d67b=dc32f988297cb3c57189ccbcd67c7069; 7a36e8ff9b36e11bfd780a779aebf1f2=4C401412+746+B+3+E55165F145F465B5C165E161413165140104F+94A5746+D1538283B2B74272E225D1618; __zlcmid=NEdVg2JezRIIXT; PHPSESSID=a81316b001465431cab6d3b8a15d118f; __utma=187962025.258322195.1391294013.1391443144.1391507878.8; __utmc=187962025; __utmz=187962025.1391426436.5.2.utmcsr=facebook.com|utmccn=(referral)|utmcmd=referral|utmcct=/; __unam=c61f6f0-143efb22cd0-e2b74ec-8; user_key=1
Host:www.portal-gestao.com
Origin:http://www.portal-gestao.com
Referer:http://www.portal-gestao.com/youbudgetz.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
addList:[{"orcamento":0,"atual":0,"desvio":"","data":"11-02-2014"}]
Response Headersview source
Cache-Control:max-age=0, no-cache, no-store
Connection:close
Content-Encoding:gzip
Content-Length:30
Content-Type:text/html
Date:Tue, 04 Feb 2014 13:57:47 GMT
Server:Apache/2.2.24 (Unix) mod_ssl/2.2.24 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_fcgid/2.3.6
Vary:Accept-Encoding
X-Mod-Pagespeed:0.9.17.7-716
X-Powered-By:PHP/5.3.24

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5290
    • View Profile
Re: PHP add, update, delete
« Reply #13 on: February 04, 2014, 07:50:38 pm »
[ Only Pro members may read this post. ]
« Last Edit: February 04, 2014, 07:52:17 pm by paramquery »

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: PHP add, update, delete
« Reply #14 on: February 04, 2014, 07:54:44 pm »
You need a user account to fetch data.

However, I have enabled data for non-users now, so you can test it.