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
Edit Sample code
12/09/2008
09:28
Avatar
YamilBracho
Member
Members
Forum Posts: 124
Member Since:
08/09/2008
sp_UserOfflineSmall Offline

Hi.

Is there some server side code to applu update to the underlying data ?

I checked the navigarot sample but the someurl.php does no have code at all just an empty php program

TIA

05/11/2008
15:57
Avatar
gmeader
Member
Members
Forum Posts: 4
Member Since:
04/11/2008
sp_UserOfflineSmall Offline

Example code to save the results of editRow to a database using PHP.

Add this to your jqGrid parameters:

editurl: 'example.php',

Here's a function to enable the row for editing when it is clicked on (see examples in jqGrid manual for editRow method):

onSelectRow: function(id){
    if(id && id!==lastSel){
        jQuery('#list2').restoreRow(lastSel);
        jQuery('#list2').editRow(id, true,on_edit,checksave);
        lastSel=id;
    }
}

Here are the two functions required by editRow() because keys is true. checksave() is the succesfunc and on_edit() is the oneditfunc.

function checksave(result) {
    // check to see if POST returns a good HTTP response
    if (result.status != 200) {
        alert(result.statusText);
         alert(”Update failed!”);
         return false;
    }
  // the PHP code sends OK as the first 2 characters if it did the db update successfully
  // if the response does not begin with 'OK'
  // display whatever is returned (probably error msgs)
    if (result.responseText.substring(0,2) != “OK”) {
        alert(result.responseText);
        return false;
    }
  return true;
}
function on_edit(result) {
        // do nothing
      return true;
}

Here is the code for example.php:

<?php
// database connection parameters
$db='';
$host='';
$user='';
$pass='';

// connect to the MySQL database server
$dbh = mysql_connect($host,$user,$pass) or die(”Connection Error: ” . mysql_error());
// select the database
mysql_select_db($db) or die(”Error selecting '$db' database.”);

// get clean id
$id=mysql_real_escape_string($_POST['id']);

$fields = '';
$values = '';
// $exceptions - fields that will not be UPDATEd into table
//               i.e. 'submit, action, '; (note trailing comma and space!)
$exceptions='submit, id, ';

// format input POST fields into SQL syntax for the list of fields and values after SET
foreach ($_POST as $field => $value) {
  if (!preg_match(”/$field, /”, $exceptions)) {
    $value = mysql_real_escape_string($value);
    $fields .= “$field = '$value', “;
  }
}
// remove trailing “, ” from $fields
$fields = preg_replace('/, $/', '', $fields);
 
$query = “UPDATE tmpsale SET $fields WHERE id='$id'”;

//echo $query;    // for debugging, any output text that does not begin with “OK” will display in an alert box      

$result = mysql_query($query);
if (!$result) {
   die('Query error:' . mysql_error());
}

if (mysql_affected_rows($dbh) > 0) {
  echo “OK\\n”;
} else {
    echo “Update Failed.\\n”;
}
?>

06/11/2008
12:41
Avatar
YamilBracho
Member
Members
Forum Posts: 124
Member Since:
08/09/2008
sp_UserOfflineSmall Offline

Thanks a lot..!

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
55 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