[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();
?>
Re: [RESOLVED] Submitting scores
OK, yet another problem. Now I'm trying to displaing the MySQL table data on an HTML page, where Name, City, Country, Score and Date are table entries, and name, city, country, score, date are variables:
PHP Code:
<html>
<body>
<?php
$username="******";
$password="******";
$database="******";
mysql_connect("*********.com" ,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM tab1";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">City</font></th>
<th><font face="Arial, Helvetica, sans-serif">Country</font></th>
<th><font face="Arial, Helvetica, sans-serif">Score</font></th>
<th><font face="Arial, Helvetica, sans-serif">Date</font></th>
</tr>
<?php
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"Name");
$city=mysql_result($result,$i,"City");
$country=mysql_result($result,$i,"Country");
$score=mysql_result($result,$i,"Score");
$date=mysql_result($result,$i,"Date");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $name; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $city; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $country; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $score; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $date; ?></font></td>
</tr>
<?php
$i++;
}
?>
</body>
</html>
I only gate a page with an empty table and I can't figure out what's wrong with the script.
You help is appreciated!
Re: [RESOLVED] Submitting scores
False alarm. :blush:
I forgot to upload the file to the server... Sorry!