Web Hosting Talk







View Full Version : SQL Whats wrong


WLHosting
04-15-2003, 07:45 PM
I have a perl script for a jokes script that somebody wants me to get running for them. The perl install script does not work. It just inserts data into the sql database. The code is as follows:
#!/usr/bin/perl

use DBI;


$dbname="";
$dbuser="";
$dbpass="";

$dbh=DBI->connect("DBI:mysql:".$dbname,$dbuser,$dbpass) or exit 1;

$dbh->do("drop table jconf");
$dbh->do(
"create table jconf(jconf_id varchar(10) primary key,".
"jconf_value integer not null)");

$dbh->do("insert into jconf(jconf_id,jconf_value) values('jonp',30)");
$dbh->do("insert into jconf(jconf_id,jconf_value) values('per',24)");

$dbh->do("drop table jip");
$dbh->do(
"create table jip(jip_id varchar(20) primary key,".
"jip_time integer not null)");


$dbh->do("drop table jcat");
$dbh->do(
"create table jcat(jcat_id integer not null auto_increment primary key,".
"jcat_name varchar(40) not null)");


$dbh->do("drop table joke");
$dbh->do(
"create table joke(joke_id integer not null auto_increment primary key,".
"jcat_id integer not null,".
"joke_caption varchar(100),".
"joke_body text,".
"joke_sname varchar(100),".
"joke_semail varchar(100),".
"joke_views integer,".
"joke_votes integer,".
"joke_sends integer,".
"joke_rating integer,".
"joke_rt float,".
"joke_added integer,".
"joke_approved integer)");

$dbh->disconnect;

I cannot run it so I am converting it over to sql and importing it in as a .sql file. I have made:

CREATE TABLE jcat (
jcat_id int(11) NOT NULL auto_increment,
jcat_name varchar(40) NOT NULL default '',
PRIMARY KEY (jcat_id)
) TYPE=MyISAM;

CREATE TABLE jconf (
jconf_id varchar(10) NOT NULL default '0',
jconf_value int(11) NOT NULL default '0',
PRIMARY KEY (jconf_id)
) TYPE=MyISAM;

INSERT INTO jconf VALUES ('jonp', 30);
INSERT INTO jconf VALUES ('per', 24);

CREATE TABLE jip (
jip_id varchar(20) NOT NULL default '0',
jip_time int(11) NOT NULL default '0',
PRIMARY KEY (jip_id)
) TYPE=MyISAM;

CREATE TABLE joke (
jcat_id integer not null,
joke_caption varchar(100),
joke_body text,
joke_sname varchar(100),
joke_semail varchar(100),
joke_views integer,
joke_votes integer,
joke_sends integer,
joke_rating integer,
joke_rt float,
joke_added integer,
joke_approved integer
)

They are not the same. I cannot get them to be the same. Can somebody help me. Thanks!

jb4mt
04-16-2003, 08:36 AM
When you say you cannot run it, what is the specific error message you are getting? Usually this will point you -- and us on this forum -- to the problematic line in the code.

WLHosting
04-16-2003, 07:24 PM
I get a 500 internal server error. I cannot get past that. I tried to convert it into the sql but I cannot get some of the fields from the .pl to work for the sql. The above is all of the .pl file and then my sql file I tried to create.

jb4mt
04-16-2003, 08:41 PM
don't just give up when you get a 500 internal server error! for one thing, try debugging from the command prompt:

perl -wc yourfilename.pl

also be sure your permissions are correct (of course)

Chas
04-16-2003, 08:56 PM
The script as you have it there is not meant to be run from a browser. I'm sure it can be run from a browser, providing the permissions are correct, but you will always get a 500 ISE. It's not printing a header for starters. It looks like it should be run from a shell to set up your tables.

Like jb4mt said, try perl -wc script.pl from the command line and see what it tells you. Post the output here if you are still stuck.

~Charlie

p.s. Did set the scalars with your DB info?

$dbname='db_name';
$dbuser='sql_user_name';
$dbpass='password';

WLHosting
04-16-2003, 09:36 PM
I did set the db info. Can somebody please help me out with just creating a sql file to upload. I have most of it but something doesn't seem to work. In the top post it shows you what I have. Can somebody please help. Thanks!

Chas
04-16-2003, 10:45 PM
These tables don't match:


create table joke (
joke_id integer not null auto_increment primary key,
jcat_id integer not null,
joke_caption varchar(100),
joke_body text,
joke_sname varchar(100),
joke_semail varchar(100),
joke_views integer,
joke_votes integer,
joke_sends integer,
joke_rating integer,
joke_rt float,
joke_added integer,
joke_approved integer
)
CREATE TABLE joke (
jcat_id integer not null,
joke_caption varchar(100),
joke_body text,
joke_sname varchar(100),
joke_semail varchar(100),
joke_views integer,
joke_votes integer,
joke_sends integer,
joke_rating integer,
joke_rt float,
joke_added integer,
joke_approved integer
)


I just glanced over the rest but this should do it.

~Charlie

WLHosting
04-17-2003, 06:49 AM
I checked it out and I got:
You have an error in your SQL syntax near 'CREATE TABLE joke (
jcat_id integer not null,
joke_caption varchar(100),
' at line 16
When I joined the sql into what I already had without any of the tries for the joke table.

digitok
04-17-2003, 06:54 AM
Try changing all the "integer" to "int" maybe...

WLHosting
04-17-2003, 07:10 AM
With integer changed to int I get:
You have an error in your SQL syntax near 'CREATE TABLE joke (
jcat_id int not null,
joke_caption varchar(100),
jo' at line 16