2011-06-08 106 views
0

我有一個腳本來檢查submitgame表,如果approve1和approve 2都不是空白,它會將數據插入到clanstats中。沒有mysql_error它只是重定向到標題而沒有插入任何東西到clanstats表中,所以我不知道發生了什麼。以下是代碼。INSERT INTO未填充數據庫表

<?php 
include("user.php"); 
$id = $_GET['id']; 
$result = mysql_query("SELECT * FROM submitgame WHERE id='$id'") or die(mysql_error()); 
$playerclan = $row['playerclan']; 
$opponentclan = $row['opponentclan']; 
$win = $row['win']; 
$approve1 = $row['approve1']; 
$approve2 = $row['approve2']; 
if($win == "won") { 
    $win = 1; 
    $points = 2; 
    $win2 = 0; 
    $points2 = 1; 
} 
else { 
    $win = 0; 
    $points = 1; 
    $win2 = 1; 
    $points2 = 2; 
} 
if($approve1 != "" && $approve2 != "") { 
    $query=mysql_query("INSERT INTO clanstats (clan, points, wins) VALUES ('$playerclan', '$points', '$win')"); 
    $query=mysql_query("INSERT INTO clanstats (clan, points, wins) VALUES ('$opponentclan', '$points2', '$win2')"); 
    echo mysql_error($query); 
} 
else { 
    header("location:../approvegames.php"); 
} 
mysql_close($con); 
header("location:../approvegames.php"); 
?> 
+0

@Alex你需要選擇的代碼,然後點擊文本區域上面的'{}'圖標以顯示代碼。基本上,它所做的只是在每行前添加四個空格,然後以代碼形式正確顯示。 – Lobo 2011-06-08 06:33:04

+0

好的,謝謝。 ^^ – vacarsu 2011-06-08 06:36:14

+0

您確定執行了兩個插入查詢嗎?我的意思是,如果$ approve1或$ approve2變量與空字符串不同? – 2011-06-08 06:38:10

回答

0
<?php 
    //first off are you connecting, ill presume so 
    include("user.php"); 
    //sql injection!!! 
    $id = mysql_real_escape_string($_GET['id']); 
    $result = mysql_query("SELECT * FROM submitgame WHERE id='$id' limit 1") or die(mysql_error()); 
    //you were missing this 
    $row=mysql_fetch_array($result); 
    $playerclan = $row['playerclan']; 
    $opponentclan = $row['opponentclan']; 
    $win = $row['win']; 
    $approve1 = $row['approve1']; 
    $approve2 = $row['approve2']; 

    if($win == "won") { 
     $win = 1; 
     $points = 2; 
     $win2 = 0; 
     $points2 = 1; 
    }else{ 
     $win = 0; 
     $points = 1; 
     $win2 = 1; 
     $points2 = 2; 
    } 

    if($approve1 != "" && $approve2 != "") { 
     //you can have multiple inserts 
     $query=mysql_query("INSERT INTO clanstats (clan, points, wins) VALUES 
     ('$playerclan', '$points', '$win'), 
     ('$opponentclan', '$points2', '$win2')"); 
     header("location:../approvegames.php"); 
     //adding die after the header will make sure nothing else gets executed 
     die(); 
    }else{ 
     header("location:../approvegames.php"); 
     die(); 
    } 
    //no need to kill the connection as it will close when the script exits 
    ?> 
+0

OH!你是絕對正確的! xD哇......我覺得很愚蠢。 >。< – vacarsu 2011-06-08 06:43:36

+0

np,玩得開心... – 2011-06-08 06:47:30

0

我認爲你錯過了一條線。也許是這樣的:

$row = mysql_fetch_row($result)