Hi,
Whithin the following code I'm getting into trouble
$db->sqlInsert("commentaire",
ref_emetteur => "1",
ref_article => "$article",
question => "$question",
text => "$text",
date => "$date $time");
package db
sub sqlInsert {
my $table = shift || '';
my(%data)=@_;
my($names,$values);
$dbh||=sqlConnect();
foreach (keys %data) {
if (/^-/) {
$values.="\n ".$data{$_}.",";
s/^-//;
}
else {
$values.="\n ".$dbh->quote($data{$_}).","; }
$names.="$_,";
}
chop($names);
chop($values);
my $sql="INSERT INTO $table ($values) VALUES ($names)\n";
#$sql = $dbh->quote ($sql);
print "Content-type: text/html\n\n";
print "$sql <br />";
if(!$dbh->do($sql)) {
my $err=$dbh->errstr;
}
}
when I print the resultat of the query on the browser it's give me the following sql
INSERT INTO MyDB=HASH(0xa22d970) ( 'text', 'question', 'ref_emetteur',
+ 'date', NULL) VALUES (,1,commentaire,
this is the description
,2013-05-31 15:16:29)
it's like the commentaire field appear in the values list and the ref_article doesn't be included but a NULL field is defined
any idea ?
thxx
In fact after doing some test on the hash, It's appear that everytime a key / value disapear
$db->sqlInsert("commentaire",
ref_article => "$article",
question => "$question",
text => "$text",
ref_emetteur => "1",
date => "$date $time");
sub sqlInsert {
my $table = shift || '';
my(%data)=@_;
print "Content-type: text/html\n\n";
while ( my ($key, $value) = each(%data) ) {
print "$value<br/>";
}
}
print out
text
date
ref_article
ref_emetteur