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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.