PHP在特定位置将值插入数据库

时间:2014-07-05 14:00:15

标签: php mysql database

所以我现在正在创建一个在线游戏并且已经登录并注册工作但现在我正在努力提交健康状况和玩家等级的统计数据并检索它。 因此,在这个PHP文件中,我能够检索某个玩家的信息,但我不知道如何将新的统计数据提交到某个玩家的行中。我还在学习PHP所以请帮帮我。

<?php
// Database Things =========================================================
$host = "localhost";
$user = "lyth_com_Spillnk";
$password = "INTERESTED?";
$dbname = "lythumn_com_Spillnk";
mysql_connect($host, $user, $password) or die("Can't connect into database");
mysql_select_db($dbname)or die("Can't connect into database");   
// =============================================================================
$Act = $_GET["Act"];// what is action, Submit or Retrieve?
$nick = $_GET["User"];
$health = $_GET["Health"];
$level = $_GET["Level"];
$xcood = $_GET["X"]; 
$ycood = $_GET["Y"];
if($Act == "Retrieve"){
        $SQL = "SELECT * FROM Stats WHERE Username = '" . $nick . "'";
        $result_id = @mysql_query($SQL) or die("DB ERROR");
        $total = mysql_num_rows($result_id);
        if($total) {
            $datas = @mysql_fetch_array($result_id);
            echo ($datas["Health"], $datas["Level"], $datas["X"], $datas["Y"]);
        }   
}
if($Act == "Submit"){
    $SQL = "SELECT * FROM Stats WHERE Username = '" . $nick . "'";
    $result_id = @mysql_query($SQL) or die("DB ERROR");

    $query = "INSERT INTO Stats (Username, Health, Level, X, Y) VALUES('$nick', '$health', '$level', $'xcood', $'ycood')";
    mysql_query($query) or die("ERROR");
    mysql_close();

    echo "Submitted";
}

// Close mySQL Connection
mysql_close();
?>

这主要是关注这段代码:

if($Act == "Submit"){
$SQL = "SELECT * FROM Stats WHERE Username = '" . $nick . "'";
$result_id = @mysql_query($SQL) or die("DB ERROR");

$query = "INSERT INTO Stats (Username, Health, Level, X, Y) VALUES('$nick', '$health', '$level', $'xcood', $'ycood')";
mysql_query($query) or die("ERROR");
mysql_close();

echo "Submitted";
}

您可以看到我已经检索了玩家统计所在位置的索引,那么如何在那里插入值?

提前致谢!

0 个答案:

没有答案