CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
What's wrong with my code??

 



iamdain
New User

Oct 22, 2011, 8:56 PM

Post #1 of 1 (419 views)
What's wrong with my code?? Can't Post

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 \n\n";

# 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."<br />";
print $lastid."<br />";

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

If I replace the lines:

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

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

With:

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

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:

<form action="xxx" method="POST">
<p> Game Name: <input type="text" name="game"/> </p>
<p> Player Name: <input type="text" name="player"/> </p>
<p> Score: <input type="text" name="score"/> </p>
<input type="submit" value="Submit"/>
</form>


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

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives