Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
How to save data in database?
28/05/2009
13:57
Avatar
JiMKE
Member
Members
Forum Posts: 3
Member Since:
28/05/2009
sp_UserOfflineSmall Offline

Hello!

Sorry my english so bad. I try to read documentation(so hard) but i can't find answer.

How to save changed, deleted or added data in database?

Anybody can post here sources of example or attached file with sources?

Thanks.

Vitaly.

28/05/2009
22:33
Avatar
xuding
xuding
Member
Members
Forum Posts: 36
Member Since:
15/11/2008
sp_UserOfflineSmall Offline

Dude,

you need some server side language to handle that.

this is a simple working copy of jqgrid+cakephp(server side language PHP)

http://www.the-di-lab.com/?p=28

Try to look at the function indexedit() in Cakephp+JqGrid\\demo\\app\\controllers\\apples_controller.

This is where it does edit,delete,and add.

Hope you can get the basic idea from here.

regards

The-Di-Lab

29/05/2009
10:54
Avatar
JiMKE
Member
Members
Forum Posts: 3
Member Since:
28/05/2009
sp_UserOfflineSmall Offline

Thanx, xuding.

This example with cakePHP so helpful for me.

But my server side wrote on pure PHP.

May be somebody can show example with pure PHP?

Deadline of my project is coming=)

Thanx.

29/05/2009
18:18
Avatar
finedesignz
Member
Members
Forum Posts: 12
Member Since:
30/05/2009
sp_UserOfflineSmall Offline

Hello,

What a great plugin!  I am also having trouble getting the edited data to the server.  Here's what I found, although I'm still having trouble getting it to work.

But since I have found almost no help on this after searching the web for hours, I thought I'd try to help...

I believe this should be the contents of 'someurl.php' (the example demo file has a blank one)

<?

// FETCHES THE 'USERS' TABLE DATA
 if($_GET[oper]=='sel'){

// connect to the MySQL database server
include 'includes/auth.inc.php';

// ADDS NEW APP RECORD - I have 5 columns, and these are the titles

} elseif($_POST[oper]=='add') {

    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $userid = $_POST['userid'];
    $start = $_POST['start'];
    $note = $_POST['note'];
    $ins = “INSERT INTO appid (fname,lname,userid,start,note) VALUES ($fname,$lname,$userid,$start,$note)”;
    @mysql_query($ins) or die(”failed”);

// MODIFIES USER RECORD
} elseif($_POST[oper]=='edit') {

    $id = $_POST['id'];
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $userid = $_POST['userid'];
    $start = $_POST['start'];
    $note = $_POST['note'];

    $upd = “UPDATE appid SET (fname,lname,userid,start,note) VALUES ($fname,$lname,$userid,$start,$note) WHERE id=$id”;
    @mysql_query($upd) or die(”failed”);

// DELETES USER RECORD AND ASSOCIATED ACCESS RELATIONSHIPS
} elseif($_POST[oper]=='del') {

    $id = $_POST['id'];

    $SQL = “DELETE FROM appid WHERE id=$id”;
    $res = @mysql_query($SQL) or die(”failed”);
 }
 mysql_close($con);

?>

However, again, I have been unable to actually get this to work.  I am hoping someone on this forum will give us more help?

Thanks in advance.

29/05/2009
21:14
Avatar
prbabu
Member
Members
Forum Posts: 22
Member Since:
11/05/2009
sp_UserOfflineSmall Offline

I would suggest read the documentation. Infact, most of the examples are in PHP-MySQL.

  It takes few days to get your head around and once you have done that "little" work, you could post like me on this forum!

-Praveen

31/05/2009
12:59
Avatar
JiMKE
Member
Members
Forum Posts: 3
Member Since:
28/05/2009
sp_UserOfflineSmall Offline

Hello, finedesignz.

Your PHP example is so simple. I understand how it works.

But how you send data in your someurl.php ?

01/06/2009
13:01
Avatar
finedesignz
Member
Members
Forum Posts: 12
Member Since:
30/05/2009
sp_UserOfflineSmall Offline

I just got mine to work… had a few minor errors (still a newbie with PHP).  The grid is awesome, works great.

I'm not sure how familiar you are with PHP, so here's my basic instructions:

To send your data to someurl.php, add the parameter to your colModel properties:

editurl: "someurl.php",

or use the navigator, which is what I did:

.navGrid('#pager',
            {add: true, edit: true, del: true, search: true}, //options
            {height:200,width:600,reloadAfterSubmit:false,url:'someurl.php'}, // edit options
            {height:200,width:600,reloadAfterSubmit:false,url:'someurl.php'}, // add options
            {reloadAfterSubmit:false,url:'someurl.php'}, // del options
            {width:600} // search options
            );

I would recommend downloading Firebug (http://getfirebug.com/) for Firefox.  It will show you what is being sent to the someurl.php page by jqgrid.  For example, Firebug shows me this after expanding the POST url:

app 11
expiration 06-01-10
id _empty
oper add
user_id 14

All of this is a simple form submission sent via POST. Once you can see the data you are processing, then you create your someurl.php, using this better basic example than the one above:

<?php

// Get information from entry
    $id = $_POST['id'];  //id field from POST above
    $exp = $_POST['expiration']; //expiration field from POST above
    $app_id = $_POST['app'];  //app field from POST above
    $user_id = $_POST['user_id'];  //user_id field from POST above

// connect to the MySQL database server
include 'includes/dbconfig.inc.php';
$con = mysql_connect($dbhost, $dbuser, $dbpassword);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
@mysql_select_db($database,$con) or die(”Error connecting to db.”);

Then set your MySQL database commands to a php variable:

 $add = “INSERT INTO table_name (user_id,app_id,expiration) VALUES ('” . $user_id . “','” . $app_id . “','” . $exp . “')”;

    $upd = “UPDATE `table_name` SET app_id = '” . $app_id . “', user_id = '” . $user_id . “', expiration = '” . $exp . “' WHERE user_id='” . $id . “'”;

    $del = “DELETE FROM table_name WHERE id='” . $id . “'”;

Finally, use php IF() to determine if you are adding, editing, or deleting a record based on the “operator” sent from above.  I like this set up because when you try to add, edit, or delete a record, it will return “License added”, etc. in Firebug so you know if it's working.

// ADDS NEW APP RECORD
if($_REQUEST[oper]=='add') {
    if (mysql_query($add,$con))
  {
  echo “License added.”;
  }
else
  {
  echo “Error adding user: ” . mysql_error();
  }

// MODIFIES USER RECORD
} elseif($_REQUEST[oper]=='edit') {

   if (mysql_query($upd,$con))
  {
  echo “User edited.”;
  }
else
  {
  echo “Error editing user: ” . mysql_error();
  }

// DELETES USER RECORD AND ASSOCIATED ACCESS RELATIONSHIPS
} elseif($_POST[oper]=='del') {
   if (mysql_query($del,$con))
  {
  echo “User deleted.”;
  }
else
  {
  echo “Error deleting user: ” . mysql_error();
  }

 }
 mysql_close($con);

?>

I'm sure some PHP pro's out there could explain it a lot better, and someone may add corrections to this post, but this is working for me.  I have 3 grids, including one subgrid, and struggled for quite a while to figure this out.  Hopefully this will help you.

JqGrid is definitely awesome!

30/08/2012
20:26
Avatar
ananthvk
India
New Member
Members
Forum Posts: 2
Member Since:
30/08/2012
sp_UserOfflineSmall Offline

A small change: you have to change the $_POST(oper) to  $_POST('oper') 

without quotes you would get parse error 200.

Regards,rnVijay

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
42 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information