Page 1 of 1

Problem trying insert data in to Mysql Datebase [solved]

Posted: Sat May 21, 2011 12:27 am
by andrewvideo
Hi I am having problems to work out this only half works,


I got working is inserting data in to module_MediaCenter_category, that fine. I want to uplate the id in module_MediaCenter_category.sql and not working. :'( am I missing out something or have I got some code worry.

Can any help and I am new to php and mysql.


Cheers

Andrew


Code: Select all


new_cat_id = $db->GenID(cms_db_prefix() . "MediaCenter_category_seq");
$catview = '0';
$catname = 'Main Videos';
$catalias = 'mainvideos';
$catactive = '1';
$query = "INSERT INTO " . cms_db_prefix() ."module_MediaCenter_category (id, viewed, modified, created, name, alias, active )
VALUES (?, ?, ?, ?, ?, ?, ?)";
# add the Data
$result = $db->Execute($query, array($new_cat_id, $catview , $db->DBTimeStamp(time()), $db->DBTimeStamp(time()),$catname,$catalias,$catactive));





Re: Problem trying insert data in to Mysql Datebase

Posted: Sat May 21, 2011 12:32 am
by calguy1000
After a query you can echo:
$db->sql --- to get the exact query that was given to mysql
$db->ErrorMsg() -- to get the error message that mysql returned.

Re: Problem trying insert data in to Mysql Datebase

Posted: Sat May 21, 2011 12:56 am
by andrewvideo
I dint get in any errors

echo $db->sql; gave me

Code: Select all

INSERT INTO cms_module_MediaCenter_category (id, viewed, modified, created, name, alias, active ) VALUES (24, '0', '\'2011-05-21 01:48:04\'', '\'2011-05-21 01:48:04\'', 'Main Videos', 'mainvideos', '1')
and $db->ErrorMsg() return noting. I am really lost now.

The data is going in 'cms_module_MediaCenter_category' fine, just not cms_module_MediaCenter_category.sql. should be adding a id number there and not.

I hope I make sence.

Cheers

Andrew

Re: Problem trying insert data in to Mysql Datebase

Posted: Sat May 21, 2011 8:19 am
by Jos
The line

Code: Select all

new_cat_id = $db->GenID(cms_db_prefix() . "MediaCenter_category_seq");
should update your sequence table and give you a new ID at the same time.

Could it be you miss something in the tablename? Should that not be like this?

Code: Select all

new_cat_id = $db->GenID(cms_db_prefix() . "module_MediaCenter_category_seq");

Re: Problem trying insert data in to Mysql Datebase

Posted: Sat May 21, 2011 9:45 am
by andrewvideo
OMG! I can't believe it. I spent hours on the is problem and it so simple to fix. I could not find the mistake.

Thank you very much Jos for help. Sometimes I find it hard to spot things like that, I have Dyslexia.

Cheers


Andrew

Re: Problem trying insert data in to Mysql Datebase [solved

Posted: Sat May 21, 2011 10:29 am
by Jos
no problem... I guess we all have these kind of mistakes we never are able to notice ourselves :D