Reputation: 13
i have a DB MySQL;
CREATE TABLE IF NOT EXISTS `obsequios` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`promocion` int(1) NOT NULL,
`dia` date NOT NULL,
`hora` time NOT NULL,
`autorizacion` varchar(30) NOT NULL,
`obsequiado_a` varchar(40) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
php code:
$sql_obsequios = '"INSERT INTO `obsequios`(`promocion`, `dia`, `hora`, `autorizacion`, `obsequiado_a`) VALUES ('.$promocion.','.'"'.$date.'"'.','.'"'.$hour.'"'.','.'"'.$user_loading.'"'.','.'"'.$regalado_a.'"'.')"';
$sql_obsequios_result = mysqli_query($con, $sql_obsequios);
if ($sql_obsequios_result) {
$result_gral = true;
}else{
$result_gral = false;
}
when I try to add data to the table, I get the value return is false. try to see the value of $ sql_obsequiosy its value is as follows:
"INSERT INTO `obsequios`(`promocion`, `dia`, `hora`, `autorizacion`, `obsequiado_a`)
VALUES (1,"2014-04-13","08:47:55","marcos","sergio")"
using phpmyadmin I have managed to successfully query. I detect what's wrong in this code
Upvotes: 0
Views: 44
Reputation: 65
Or try:
$sql_obsequios = "INSERT INTO obsequios(promocion, dia, hora, autorizacion, obsequiado_a) VALUES ('.$promocion.',''.$date.'',''.$hour.'',''.$user_loading.'',''.$regalado_a.'')";
$sql_obsequios_result = mysql_query(sql_obsequios);
if ($sql_obsequios_result) {
$result_gral = true;
}else{
$result_gral = false;
}
Upvotes: 1
Reputation: 7769
Try this:
$sql_obsequios = "INSERT INTO `obsequios`(`promocion`, `dia`, `hora`, `autorizacion`, `obsequiado_a`) VALUES ('$promocion','$date','$hour','$user_loading','$regalado_a')";
$sql_obsequios_result = mysql_query(sql_obsequios);
if ($sql_obsequios_result) {
$result_gral = true;
}else{
$result_gral = false;
}
Upvotes: 1
Reputation: 2414
Try this and see the difference:
$sql_obsequios = "
INSERT INTO `obsequios`
(`promocion`, `dia`, `hora`, `autorizacion`, `obsequiado_a`)
VALUES
('".$promocion."','".$date."','".$hour."','".$user_loading."','".$regalado_a."')";
Also, I dont see any call of mysql_query()
or something to get $sql_obsequios_result
Upvotes: 1
Reputation: 65
Where is Your instructions to add data to DB ?
$sql_obsequios = ...
if ($sql_obsequios_result) ...
it is not the same
Upvotes: 1