Forum


19:41

13/06/2011

Greetings Folks,
I have an issue with the insertion of a date field in the database, here is my grid.php
/**
* @author Ahmed Ossama
* @copyright 2011
*/
session_start();
// require_once 'jq-config.php';
define('DB_DSN','mysql:host=localhost;dbname=videos');
define('DB_USER', 'ahmed');
define('DB_PASSWORD', 'P4ssW0rd');
define('ABSPATH', dirname(__FILE__).'/');
// include the jqGrid Class
require_once ABSPATH."php/jqGrid.php";
// include the driver class
require_once ABSPATH."php/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN, DB_USER, DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqGrid instance
$grid = new jqGridEdit($conn);
// enable debugging
// $grid->debug = true;
// Write the SQL Query
$grid->SelectCommand = 'SELECT * FROM videos WHERE owner_id = ?';
// set the user date format to m/d/Y
$grid->setUserDate('m/d/Y');
// tell the grid which field is date
$grid->datearray = array('date_added');
// Set the table to where you update the data
$grid->table = 'videos';
$grid->setPrimaryKeyId('id');
// Set output format to json
$grid->dataType = 'json';
$user_id = $_SESSION['user_id'];
$data = $_POST;
switch ($_POST['oper']) {
case "add":
$data = array(
"uniq_id"=>substr(md5(rand(99999, 9999999999)), 1, 9),
"caption"=>$_POST['caption'],
"video_link"=>$_POST['video_link'],
"owner_id"=>$user_id,
"date_added"=>date('Y-m-d')
);
$grid->insert($data);
break;
case "edit":
$grid->editGrid();
break;
case "del":
$grid->delete($data);
break;
default:
$grid->queryGrid(null, array($user_id));
break;
}
?>
and here is my grid js
jQuery(document).ready(function($) {
jQuery('#grid').jqGrid({
"width":"650",
"hoverrows":true,
"viewrecords":true,
"jsonReader":{
"repeatitems":false,
"subgrid":{"repeatitems":false}
},
"xmlReader":{
"repeatitems":false,
"subgrid":{"repeatitems":false}
},
"gridview":true,
"url":"libs/grid.php",
"editurl":"libs/grid.php",
"cellurl":"libs/grid.php",
"altRows":true,
"autowidth":true,
"caption":"eBridge Training Videos [<a href=\"/logout.php\" style=\"color: red;\">Logout</a>]",
"colNames":["ID","Caption","Video","Date Added"],
"height":"auto",
"rowNum":15,
"rowList":[15,25],
"sortname":"date_added",
"sortorder":"desc",
"datatype":"json",
"colModel":[
{"name":"uniq_id","index":"uniq_id","sorttype":"string","editoptions":{"readonly":true},"editable":false,"align":"center","width":20},
{"name":"caption","index":"caption","sorttype":"string","editable":true,"editrules":{"required":true,"edithidden":true},"edittype":"text","editoptions":{"width":600,"maxlength":255}},
{"name":"video_link","index":"video_link","sorttype":"blob","hidden":true,"editable":true,"editrules":{"required":true,"edithidden":true},"edittype":"textarea","editoptions":{"width":600,"rows":7,"cols":70}},
{"name":"date_added","index":"date_added","sorttype":"date","width":20,"formatter":"date","formatoptions":{"srcformat":"Y-m-d","newformat":"m/d/Y"},"search":true,"align":"center","editoptions":{"readonly":true},"editable":false}],
"postData":{"oper":"grid"},
"prmNames":{"page":"page","rows":"rows","sort":"sidx","order":"sord","search":"_search","nd":"nd","id":"id","filter":"filters","searchField":"searchField","searchOper":"searchOper","searchString":"searchString","oper":"oper","query":"grid","addoper":"add","editoper":"edit","deloper":"del","excel":"excel","subgrid":"subgrid","totalrows":"totalrows","autocomplete":"autocmpl"},
"loadError":function(xhr,status, err) {
try {jQuery.jgrid.info_dialog(jQuery.jgrid.errors.errcap,'<div class="ui-state-error">'+ xhr.responseText +'</div>', jQuery.jgrid.edit.bClose,{buttonalign:'right'});}
catch(e) { alert(xhr.responseText);}
},
"pager":"#pager",
ondblClickRow: function (rowid,iRow,iCol,e) {
var id = jQuery("#grid").jqGrid('getGridParam','selrow');
var ret = jQuery("#grid").jqGrid('getRowData',id);
var video_url = ret.uniq_id;
// alert(video_url);
window.open('/watch/'+video_url);
}
});
jQuery('#grid').jqGrid('navGrid','#pager',
{ "edit":true, "add":true, "del":true, "search":true, "refresh":true, "view":false, "excel":true, "pdf":false, "csv":false, "columns":false },
{ "drag":true, "resize":true, "closeOnEscape":true, "dataheight":150, "errorTextFormat":function(r) { return r.responseText;}, "width":600, "recreateForm":true, "closeAfterEdit":true, "editCaption":"Edit Video Link", "bSubmit":"Update","mtype":"POST"},
{ "drag":true,"resize":true,"closeOnEscape":true,"dataheight":150,"errorTextFormat":function(r){ return r.responseText;},"width":600,"recreateForm":true,"closeAfterAdd":true,"addCaption":"Add Video Link","bSubmit":"Add","mtype":"POST"},
{ "errorTextFormat":function(r){ return r.responseText;},"mtype":"POST"},
{ "drag":true,"closeAfterSearch":true,"multipleSearch":true},
{ "drag":true,"resize":true,"closeOnEscape":true,"dataheight":150,"width":600,"recreateForm":true,"closeAfterEdit":true,"addCaption":"View Video Link","bSubmit":"Add"});
jQuery('#grid').jqGrid('navButtonAdd','#pager',
{id:'pager_excel', caption:'',title:'Export To Excel',onClickButton : function(e) {
try { jQuery("#grid").jqGrid('excelExport',{tag:'excel', url:'libs/grid.php'}); }
catch (e) { window.location= 'libs/grid.php?oper=excel'; }
},buttonicon:'ui-icon-newwin'});
});
</script>
and here is my debugging log (jqGrid.log):
Array
(
[0] => Array
(
[time] => 2011-06-12 10:39:50
[query] => SELECT * FROM videos WHERE 1=2
[data] =>
[types] =>
[fields] =>
[primary] =>
[input] =>
)
[1] => Array
(
[time] => 2011-06-12 10:39:50
[query] => INSERT INTO videos (uniq_id, caption, video_link, owner_id, date_added) VALUES( ?, ?, ?, ?, ?)
[data] => Array
(
[0] => b99967390
[1] => bhmfgtthft
[2] => hfchgfhfghfgh
[3] => 1
[4] => 1970-01-01
)
[types] => Array
(
[0] => string
[1] => string
[2] => blob
[3] => int
[4] => date
)
[fields] => Array
(
[id] => Array
(
[type] => int
)
[uniq_id] => Array
(
[type] => string
)
=> Array
(
[type] => string
)
[video_link] => Array
(
[type] => blob
)
[owner_id] => Array
(
[type] => int
)
[date_added] => Array
(
[type] => date
)
)
[primary] => id
[input] => Array
(
[uniq_id] => b99967390
=> bhmfgtthft
[video_link] => hfchgfhfghfgh
[owner_id] => 1
[date_added] => 2011-04-04
)
)
)
The problem is that the date goes into the database 1970-01-01, I have tried even setting the date with a default value in the grid.php array, but still the date is entered 1970-01-01.
Any help is very much appreciated.
Thanks in advance
23:15

Moderators
30/10/2007

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
49 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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66