Reputation: 518
I am trying to save data in two different database tables , when i run two query it save 0 in the integer field.
$sql = 'insert into photo_album( user_id, photo_id, album_id )
values(". $user_id.",".$photo_id.",". $album_id.")';
$query = $this->db->query($sql);
but when i run query as hard coded values it work fine.
INSERT INTO
photo_album( photo_id, user_id, album_id )
VALUES(8299,214,316)
can some one tell what is wrong ?
Upvotes: 2
Views: 292
Reputation: 518
finely i manage to solve this issue , It is very strange you people will laugh at me / not believe me , I rename the field to some other name it start saving the value again , then i again rename to original name , I saw every this is working perfectly.
Thank you for your help.
please tell me if this is bug in mysql or not
Upvotes: 0
Reputation: 11859
since you are using codeigniter
then try like this:
$dataArr = array(
'photo_id' => $photo_id,
'user_id' => $user_id,
'album_id' => $album_id
);
$this->db->insert('photo_album', $dataArr);
Upvotes: 0
Reputation: 59681
This should work for you:
(Don't mix single and double quotes! They are different :D)
$sql = "INSERT INTO `photo_album`(photo_id, user_id, album_id)
VALUES('" . $photo_id . "', '" . $user_id . "', '" . $album_id . "')";
EDIT after comment:
Then try it to put '
around the values. Maybe the are stored as strings.
Also don't change the order of the column's to insert :D
Upvotes: 0
Reputation: 37
Try this
$sql="INSERT INTO photo_album (user_id,photo_id,album_id)
VALUES('$this->user_id','$this->photo_id','$this->album_id')";
Upvotes: 0
Reputation: 150
$data = array(
'user_id' => '$user_id' ,
'photo_id' => '$photo_id' ,
'album_id' => '$album_id'
);
$this->db->insert('photo_album', $data);
Upvotes: 1
Reputation: 1667
Try This Separate variables
$sql = 'insert into photo_album( `user_id`, `photo_id`, `album_id` )
values("' .$user_id. '","' .$photo_id. '","' .$album_id. '")';
Upvotes: 0
Reputation: 1796
try like this in codeigniter format
$data = array(
'user_id' => $user_id,
'photo_id' => $photo_id,
'album_id' => $album_id
);
$this->db->insert('photo_album', $data);
Upvotes: 0