2017-08-24 106 views
0

我想爲我的網站做一個商店,所以我需要MySQL。 我想從用戶那裏拿走50金幣,並給予5點金幣。 我的當前腳本如下所示:需要MySQL數據庫的PHP腳本

<?php 
ob_start(); 
session_start(); 
print('<meta http-equiv="content-type" content="text/html; charset=UTF-8" 
/>'); 
include('config.php'); 

if(isset($_SESSION['rank']) && $_SESSION['rank'] >= 1) 
{ 
    if(isset($_SESSION['Gold']) && $_SESSION['Gold'] >= 50) 
    { 
mysql_query("UPDATE users SET Gold = $_SESSION[Gold]-50 WHERE id = 
$_SESSION[id];"); 
mysql_query("UPDATE users SET AtkDmg = $_SESSION[AtkDmg] + 5' WHERE id = 
$_SESSION[id];"); 
    } else header('location: shop.php'); 
} else header('location: login.php'); 
mysql_close() 
?> 

什麼是會話?這就是:

<?php 
ob_start(); 
session_start(); 

include('config.php'); 
include('login_form.php'); 

    if(isset($_POST["login"])){ 

    $nickname = $_POST["nickname"]; 
    $password = md5($_POST["password"]); 
    $lekerdezes = mysql_query("SELECT * FROM users WHERE nickname = 
'".mysql_real_escape_string($nickname)."' AND password = '$password'"); 
    $vanelekerdezes = mysql_num_rows($lekerdezes); 
    if ($vanelekerdezes>0) 
    { 
     header('location: login.php'); 
     $adatok=mysql_fetch_assoc($lekerdezes); 
     $_SESSION["id"]=$adatok["id"]; 
     $_SESSION['bann'] = 0; 
     $_SESSION["nickname"]=$adatok["nickname"]; 
     $_SESSION["rank"]=$adatok["rank"];  
     $_SESSION["Gold"]=$adatok["Gold"]; 
     $_SESSION["AtkDmg"]=$adatok["AtkDmg"]; 
    } 
    else 
    { 
    print 'Hibás felhasználónév vagy jelszó!'; 
    print mysql_error(); 
    } 



    } else if(isset($_SESSION["nickname"])){ 


    header('location: home.php'); 
    } 



?> 

我希望你能幫助我,我還在學習PHP的,所以也許這就是爲什麼我不能修復這個簡單的事......所以,如果你這樣寫:學習PHP的,我「M已經這樣做:)

+0

的sooo ...這是什麼問題?你有什麼錯誤嗎?也許可以快速瀏覽[如何提出問題](https://stackoverflow.com/help/how-to-ask)? – Naruto

+0

它沒有做任何事情,我得到一個空白頁面,抱歉的問題不好。 – hunzeno

+1

'mysql_ *'api已棄用嘗試使用'mysqli_ *或pdo' – JYoThI

回答

0

一是調整會話VAR:

$gold = $_SESSION['Gold'] = $_SESSION['Gold'] - 50; 
$attackDamage = $_SESSION['AtkDmg'] = $_SESSION['AtkDmg'] + 5; 

編輯您的SQL字符串是這樣的:

"UPDATE users SET AtkDmg = $attackDamage etc etc 
+0

它將我的黃金和atkdmg設置爲0. – hunzeno

+0

ok我已經編輯過,試試這個 – delboy1978uk

+0

完美的作品,太好了,你是最棒的! – hunzeno

相關問題