Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't INSERT immediately after CREATE TABLE 1

Status
Not open for further replies.

poplarman

IS-IT--Management
Dec 15, 2001
12
US
I'm using embedded MySql statements in Perl to create a table and insert the first record. My code is:

$sth = $dbh->prepare ("
CREATE TABLE TEST (
`product` varchar(16) NOT NULL default '',
`title` varchar(40) NOT NULL default 'No Title',
`desc` longtext NOT NULL,
`image` varchar(24) NOT NULL default 'no-image.gif',
`price` decimal(10,2) NOT NULL default '0.00',
PRIMARY KEY (`product`)
)");
$sth->execute ();

$dbh->prepare ("INSERT INTO TEST VALUES ('a', 'b', 'c', 'd', 9999)");
$sth->execute ();

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

When I go into phpMyAdmin The table is there but no record has been inserted. When I INSERT a record from phpMyAdmin it works fine. The program ends OK with the right displays.

Please help - this is holding me up.
 
I have negative experience with Perl. However, from context clues, I may have found something. Try this:

$sth = $dbh->prepare ("
CREATE TABLE TEST (
`product` varchar(16) NOT NULL default '',
`title` varchar(40) NOT NULL default 'No Title',
`desc` longtext NOT NULL,
`image` varchar(24) NOT NULL default 'no-image.gif',
`price` decimal(10,2) NOT NULL default '0.00',
PRIMARY KEY (`product`)
)");
$sth->execute ();

$sth = $dbh->prepare ("INSERT INTO TEST VALUES ('a', 'b', 'c', 'd', 9999)");
$sth->execute ();

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


*cLFlaVA
----------------------------
When will I be able to see what other members can see about myself? It's been like, a freakin' month already!
 
wow - I can't believe you solved it so quickly - it worked 1st time.

Many, many thanks.

Bob_H
 
Unfamiliarity with a language sometimes makes it easier to notice what's wrong, I guess...

*cLFlaVA
----------------------------
When will I be able to see what other members can see about myself? It's been like, a freakin' month already!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top