所以我一直在研究一个国家模拟器游戏。它将在线,我有很多CSS和HTML的经验,但不是PHP。我也有很多Java和C ++的经验。我有数据库设置,并使用功能登录和注册系统,以及显示各国当前统计数据的功能成员索引。但是,我完全无法弄清楚如何制作一个可以改变国家名称和当前可用资金等用户信息的脚本。这是我对一个人的微弱尝试:(它试图在总数中添加10个建筑物.SESS_是会话中的变量)
<?php
//Start session
session_start();
//Include database connection details
require_once('config.php');
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$result = mysql_query("UPDATE members SET buildings ='10' WHERE login='SESS_NATION'")
or die(mysql_error());
$result = mysql_query("SELECT * FROM members WHERE login='SESS_NATION'")
or die(mysql_error());
// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
echo $row['login']." - ".$row['Buildings']. "<br />";
?>
答案 0 :(得分:1)
如果您的变量在会话中,请尝试:
//or if a constant then, $result = mysql_query("UPDATE members SET buildings ='10' WHERE login='".SESS_NATION."'") or die(mysql_error()); //first one $result = mysql_query("UPDATE members SET buildings ='10' WHERE login='".$_SESSION['SESS_NATION']."'") or die(mysql_error());
希望有所帮助