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

In reply to regular expression trouble by *alexandre*

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.