Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.