Author Topic: PHP add, update, delete  (Read 27414 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: 6318
    • View Profile
Re: PHP add, update, delete
« Reply #1 on: February 03, 2014, 06:56:33 pm »
PHP code is same as given in the PHP tab.

Rather there are few differences w.r.t URLs for PHP.

I've added comments in js code relevant to PHP

Enable the lines for PHP and comment out the lines specific to ASP.NET
« 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: 6318
    • View Profile
Re: PHP add, update, delete
« Reply #3 on: February 04, 2014, 12:46:00 am »
data for new rows is sent from line 38 to 50 in js

Did you remove / comment out all lines specific to ASP.NET e.g.

contentType: "application/json; charset=utf-8",//for ASP.NET

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: 6318
    • View Profile
Re: PHP add, update, delete
« Reply #5 on: February 04, 2014, 01:33:10 am »
Could I have a look at your entire js code or a URL.

Your Ajax Call derives from ajaxObj, so more specifically, what's your code in ajaxObj?
« 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: 6318
    • View Profile
Re: PHP add, update, delete
« Reply #7 on: February 04, 2014, 05:14:53 pm »
WHat do you get with

if( isset($_POST["addList"]))           
{
   var_dump ($_POST["addList"]);

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: 6318
    • View Profile
Re: PHP add, update, delete
« Reply #9 on: February 04, 2014, 05:33:24 pm »
Let's try to narrow down the problem.

Try this

data: { "addList": '[{"UnitPrice":"10","Discontinued":false,"ProductName":"new ","QuantityPerUnit":"1","UnitsInStock":"1"}]'  },

instead of

data: { "addList": JSON.stringify(addList) },



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: 6318
    • View Profile
Re: PHP add, update, delete
« Reply #11 on: February 04, 2014, 07:12:28 pm »
Could you send the whole Header log in Firefox (firebug) or chrome (developer tools).
like this:

Request URL:http://localhost:81/paramquery/products.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:en-US,en;q=0.8,es;q=0.6
Connection:keep-alive
Content-Length:182
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:PHPSESSID=5c7t0ltct2jto36ppe2stv6875
Host:localhost:81
Origin:http://localhost:81
Referer:http://localhost:81/paramquery/editing_batch.php
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
addList:[{"UnitPrice":"10","Discontinued":false,"ProductName":"new ","QuantityPerUnit":"1","UnitsInStock":"1"}]
Response Headersview source
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Length:249
Content-Type:text/html; charset=UTF-8
Date:Tue, 04 Feb 2014 12:01:23 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=100
Pragma:no-cache
Server:Apache/2.4.4 (Win32) PHP/5.4.15
X-Powered-By:PHP/5.4.15
« 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: 6318
    • View Profile
Re: PHP add, update, delete
« Reply #13 on: February 04, 2014, 07:50:38 pm »
I wonder, how are you testing your application when this URL is not working properly (not loading data).

http://www.portal-gestao.com/youbudgetz.html

I believe it was fixed earlier. Am I missing something.

The below url is also not working. throwing SQL error.....

http://www.portal-gestao.com/budget/incluir/json4.php

Code: [Select]
Erro com o JSON exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 10' in /home/portalge/public_html/budget/incluir/json4.php:71 Stack trace: #0 /home/portalge/public_html/budget/incluir/json4.php(71): PDO->query('SELECT DATE_FOR...') #1 {main}

Could you please set it right, so that I could have a look.

« 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.