Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 11th, 2000, 02:12 AM
chrisdice4 chrisdice4 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Cape Town, WP, South Africa
Posts: 39 chrisdice4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Hi there

Is it possible to have an insert into sql in a for loop, below is the code that prints the parameters but does not insert the code into my database.

cerlbinperl.exe;

use CGI;
use DBI;

$q = new CGI;

print $q->header;
print "<html>
<head>
</head>
<body><table>";
$check = $q->param('1&&size');
$voy = $q->param("voyage");
$repid = $q->param("repid");
$trade = $q->param("trade");


$dbh = DBI->connect('DBI:ODBC:salesforecast',' ',' ')
| | die print "cant connect to ODBC";

for ($s=1; $s<10;$s++)

{
$checkforecast = $q->param("$s&&forcast");
$customerid = $q->param("$s&&customerid");
$customer = $q->param("$s&&customer");
$amount =$q->param("$s&&amount");
$siz = $q->param("$s&&size");
$type = $q->param("$s&&type");
$weight = $q->param("$s&&weight");
$pol = $q->param("$s&&POL");
$pod = $q->param("$s&&pod");

if ($checkforecast eq "on")
{


$sth = $dbh->do("INSERT INTO Forecast ( Voyage, CustomerID, Size, Type, Weight, POL, POD, Trade, Repid )
VALUES ('$voy',
'$customerid',
'$siz',
'$type',
'$weight',
'$pol',
'$pod',
'$trade',
'$repid')");


print "<tr>
<td>$checkforecast</td>
<td>$voy</td>
<td>$customer</td>
<td>$amount</td>
<td>$siz</td>
<td>$type</td>
<td>$weight</td>
<td>$pol</td>
<td>$pod</td>
<td>$trade</td>
<td>$repid</td>
</tr>";
}


}

print "</table></body></html>";

$sth->finish;
$dbh->disconnect;


Any help would be aprreciated


Reply With Quote
  #2  
Old October 11th, 2000, 02:53 AM
MeijdenB MeijdenB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: Alkmaar, The Netherlands
Posts: 123 MeijdenB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Do it like this, using the prepare() and execute() functions:

cerlbinperl.exe;

use CGI;
use DBI;

$q = new CGI;

print $q->header;
print "<html>
<head>
</head>
<body><table>";
$check = $q->param('1&&size');
$voy = $q->param("voyage");
$repid = $q->param("repid");
$trade = $q->param("trade");


$dbh = DBI->connect('DBI:ODBC:salesforecast',' ',' ') | | die print "cant connect to ODBC";

$sth = $dbh->prepare("INSERT INTO Forecast ( Voyage, CustomerID, Size, Type, Weight, POL, POD, Trade, Repid ) VALUES (?,?,?,?,?,?,?,?,?)");

for ($s=1; $s<10;$s++)
{
$checkforecast = $q->param("$s&&forcast");
$customerid = $q->param("$s&&customerid");
$customer = $q->param("$s&&customer");
$amount =$q->param("$s&&amount");
$siz = $q->param("$s&&size");
$type = $q->param("$s&&type");
$weight = $q->param("$s&&weight");
$pol = $q->param("$s&&POL");
$pod = $q->param("$s&&pod");

if ($checkforecast eq "on")
{
$sth = $dbh->execute($voy,$customerid,$siz,$type,$weight,$pol,$pod,$trade,$repid);

print "<tr>
<td>$checkforecast</td>
<td>$voy</td>
<td>$customer</td>
<td>$amount</td>
<td>$siz</td>
<td>$type</td>
<td>$weight</td>
<td>$pol</td>
<td>$pod</td>
<td>$trade</td>
<td>$repid</td>
</tr>";
}


}

print "</table></body></html>";

$sth->finish;
$dbh->disconnect;

------------------
Good luck,
Bas

------------------
E-mail me at: b.vandermeijden@pecoma.nl

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Insert into (sql) in for loop


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT