
iamdain
New User
Oct 22, 2011, 8:56 PM
Post #1 of 1
(290 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: ---------------------
#!/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...
|