Php 插入到不填充数据库表中
我有一个检查SubmitName表的脚本,如果approve1和Approve2都不是空的,它会将数据插入clanstats。没有mysql_错误,它只是重定向到头,而没有在clanstats表中插入任何内容,所以我不知道发生了什么。下面是代码Php 插入到不填充数据库表中,php,Php,我有一个检查SubmitName表的脚本,如果approve1和Approve2都不是空的,它会将数据插入clanstats。没有mysql_错误,它只是重定向到头,而没有在clanstats表中插入任何内容,所以我不知道发生了什么。下面是代码 <?php include("user.php"); $id = $_GET['id']; $result = mysql_query("SELECT * FROM submitgame WHERE id='$id'") or die(mysql_
<?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");
?>
我想你漏了一行。也许是这样的:
$row = mysql_fetch_row($result)
@Alex您需要选择代码并单击文本区域上方的{}图标以显示代码。基本上,它只需在每行前面添加四个空格,就可以正确地显示为代码。您确定执行了两个insert查询吗?我的意思是,如果$approve1或$approve2变量与空字符串不同,您是否尝试过使用var_转储$approve1和$approve2的值?另外,始终使用exit/die after header'Location:…'语句,以避免进一步执行代码时出现意外结果。请稍候。。您的$结果如何变成$行?。。你不应该在中间有MySqLyFuffChyAsSOC吗?在这一切之上,如果我决定手动更改URL为……ID=’,你就被拧了。将表格提交给我;-即
<?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
?>