Forums

[OK]Insertion into a table

picsoung 10 Feb, 2009
Hey🙂

my forms and sessions are working🙂 thanks again for you help🙂
now i would like to store this informations into the database.
So i have a tablle called jos_serial with 3 field (id (autoincrement, primarykey), iduser,serial)
i want my submit button to insert information on the database
so here is my code :

<?php $session    =& JFactory::getSession();
$sn=$session->get('sn');
echo $sn;

$user =& JFactory::getUser();
$usr_id = $user->get('id');


$db =& JFactory::getDBO();
$query= 'INSERT INTO #__serial (iduser,SN)' . ' VALUES ('.$usr_id.','.$sn.')';
$db->setQuery($query);
$db->query();
?>


But it's not working, i dont have any error, and nothing on my table.

but if i do
$query= 'INSERT INTO #__serial (iduser,SN)' . ' VALUES ('.$usr_id.',"blabla")';

is working...

i dont realy understand why...
iduser is INT, SN is VARCHAR(10).
my variable $sn is correct beacause "echo $sn" is working well..

Do you have an idea ?

thanks😉
GreyHead 10 Feb, 2009
Hi Patrice,

It will be something to do with the quotes, try
$query= "
    INSERT 
        INTO `#__serial` (iduser, SN) 
        VALUES ( '$usr_id', '$sn' )";
or I prefer
$query= "
    INSERT 
        INTO `#__serial` 
        SET `iduser` =  '$usr_id',
            `SN` = '$sn' ;";

Bob
picsoung 10 Feb, 2009
so great !😀
thanks😉
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger