What's wrong with my code? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

What's wrong with my code?

iamdainiamdain Posts: 2Member
I'm a total noob to Perl. Why isn't this working?? I don't get an error message, it just returns '0' and nothing is added to the database:

---------------------
[CODE]#!/usr/bin/perl

use Mysql;
use CGI;
use DBI;

print "Content-type: text/html

";

# Read form data etc. dh
my $cgi = new CGI;

my $game = $cgi->param('game');#next 3 dh
my $playerName = $cgi->param('player');
my $score = $cgi->param('score');

exit 0 unless $game; # dh

# MYSQL CONFIG VARIABLES
$host = "xxxx";
$database = "xxxx";
$tablename = "xxxx";
$user = "xxxx";
$pw = "xxxx";

# PERL MYSQL CONNECT()
$connect = Mysql->connect($host, $database, $user, $pw);

# SELECT DB
$connect->selectdb($database);

# DEFINE A MySQL QUERY
$myquery = "INSERT INTO $tablename (game, player, score) VALUES (?,?,?)";

# PREPARE THE QUERY FUNCTION DH
$execute = $connect->prepare($myquery);

# EXECUTE THE QUERY FUNCTION DH
$execute->execute($games, $player, $score);

# AFFECTED ROWS
$affectedrows = $execute->affectedrows($myquery);

# ID OF LAST INSERT
$lastid = $execute->insertid($myquery);

print $affectedrows."
";
print $lastid."
";[/CODE]

-------------------------------

If I replace the lines:

[CODE]# PREPARE THE QUERY FUNCTION DH
$execute = $connect->prepare($myquery);

# EXECUTE THE QUERY FUNCTION DH
$execute->execute($games, $player, $score); [/CODE]

With:

[CODE]# EXECUTE THE QUERY FUNCTION
$execute = $connect->query($myquery); [/CODE]

And I put explicit VALUES in the definition of $myquery preceding this line the values are inserted with no issues...

If it helps at all the HTML form code I'm using is:

[CODE]

Game Name:

Player Name:

Score:


[/CODE]


What's goin on here? I feel like my code matches every example I can find to a tee...
Sign In or Register to comment.