|
-
Nov 7th, 2009, 03:21 PM
#1
Thread Starter
Member
[RESOLVED] Submitting scores
Hi,
I want to submit game scores to different MySql tables (tab1-tab2) according to the type of the game (1-4).
The PHP code reads the score, some more data and the type of game, stored in $gametype. then it goes through elseif statements to choose the right table.
However, something is not working in this code.
Can someone see a syntax error that I'm not able to see?
Thanks!
PHP Code:
<?
$username="******";
$password="******";
$database="******";
$gametype=0
// Connect to database
mysql_connect ("***********.com" , $username, $password) or die( "cannot connect" );
mysql_select_db($database) or die ("cannot open" );
//if(isset($_GET['name'], $_GET['score']))
if(isset($_GET['name'], $_GET['city'], $_GET['country'], $_GET['score'], $_GET['date'], $_GET['gametype']))
{
$name = mysql_real_escape_string($_GET['name']);
$city = mysql_real_escape_string($_GET['city']);
$country = mysql_real_escape_string($_GET['country']);
$score = (int) $_GET['score'];
$date = mysql_real_escape_string($_GET['date']);
$gametype = (int) $_GET['gametype']);
print ($gametype);
if ($gametype == 1) {
$result = mysql_query ("INSERT INTO tab1 (Name,City,Country,Score,Date) VALUES ('$name','$city','$country','$score','$date')");
} elseif ($gametype == 2) {
$result = mysql_query ("INSERT INTO tab2 (Name,City,Country,Score,Date) VALUES ('$name','$city','$country','$score','$date')");
} elseif ($gametype == 3) {
$result = mysql_query ("INSERT INTO tab3 (Name,City,Country,Score,Date) VALUES ('$name','$city','$country','$score','$date')");
} elseif ($gametype == 4) {
$result = mysql_query ("INSERT INTO tab4 (Name,City,Country,Score,Date) VALUES ('$name','$city','$country','$score','$date')");
}
if($result)
echo 'score submitted!';
mysql_close();
?>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|