Hello all
Iam making a simple scripted program that can read and write to a mysql database using html forms. I can search the database fine so far. Bu now i am trying to insert data into the database table but it just doesnt wanna work. I think its somthing todo with the param part of the program as i was using one param fields before but now going to use two.
Heres the code for the inserting of data.
#!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use vars qw($Query $Query2 $dbh $sth $Value $Data1 $Data2); my @results; my @row; use DBI; $Query = new CGI( ); $dbh = DBI->connect("DBI:mysql:exelstock") or die "Cannot connect: " . $DBI::errstr; $Data1 = $Query->param('Value4'); $Data2 = $Query->param('Value5'); $sth = $dbh->prepare("INSERT INTO walstock (sid, name, qty) VALUES (DE +FAULT, $Data1, $Data2)"); $sth->execute(); print "Content-type: text/html\n\n"; print "<HTML>\n"; print "<BODY>\n"; print "<HEAD><TITLE>Insert Records</TITLE></HEAD>\n"; $sth = $dbh->prepare("SELECT * FROM walstock WHERE name='$Data1'"); $sth->execute(); while (@row = $sth->fetchrow_array) { print "@row\n"; } $sth = $sth->finish(); $dbh->disconnect(); print "</BODY>\n"; print "</HTML>\n";
Trying to do this for a university project, any help would be great thanks all

Edited by Chady -- added code tags.

2005-03-21 Edited by Arunbear: Changed title from 'Was working but now this part doesnt', as per Monastery guidelines


In reply to Problems inserting values in mysql database by ginda

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.