Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MYSQL/PHP语法错误_Php_Mysql_Syntax - Fatal编程技术网

MYSQL/PHP语法错误

MYSQL/PHP语法错误,php,mysql,syntax,Php,Mysql,Syntax,下面是我页面顶部的php代码: if(!$_SESSION['username']){ header("Location: ../error.php?id=1"); } $teamgamertag = $_POST["gamertag"]; $teamgame = $_POST["game"]; $teamtype = $_POST["type"]; $teamname = $_POST["name"]; $teamconsole = $_POST["console"]; if(isse

下面是我页面顶部的php代码:
if(!$_SESSION['username']){
  header("Location: ../error.php?id=1");
}

$teamgamertag = $_POST["gamertag"];
$teamgame = $_POST["game"];
$teamtype = $_POST["type"];
$teamname = $_POST["name"];
$teamconsole = $_POST["console"];

if(isset($_POST["submit"])){
  $sql2 = mysql_query("INSERT INTO teams (name, game, players, creator, console, leaders, type, score) VALUES ('$teamname', '$teamgame', '$teamgamertag', '$teamgamertag', '$teamconsole', '$teamgamertag', '$teamtype', '0'") or die(mysql_error());

  if($sql2){
    header("../results.php?id=1");
  }else{
    exit();
  }
}
?>

我不知道问题是什么,在哪里解决它。提前感谢您的帮助。

SQL查询的结尾括号缺失:

'$teamgamertag', '$teamtype', '0'")
应该在这里:

'$teamgamertag', '$teamtype', '0')")
此外,SQL易受注入攻击。不要手动生成查询字符串。使用准备好的语句:

将代码替换为

<?php
if(!$_SESSION['username']){
  header("Location: ../error.php?id=1");
}

$teamgamertag = $_POST["gamertag"];
$teamgame = $_POST["game"];
$teamtype = $_POST["type"];
$teamname = $_POST["name"];
$teamconsole = $_POST["console"];

if(isset($_POST["submit"])){
  $sql2 = mysql_query("INSERT INTO teams (name, game, players, creator, console, leaders, type, score) VALUES ('$teamname', '$teamgame', '$teamgamertag', '$teamgamertag', '$teamconsole', '$teamgamertag', '$teamtype', '0')") or die(mysql_error());

  if($sql2){
    header('Location: ../results.php?id=1');
  }else{
    exit();
  }
}
?>

这里没有明显的语法错误,除了缺少开头
@NicholasPickering它在SQL中缺少
您的第二个头的格式不正确这是“不是一个真正的问题”的完美例子。另外,从手动
HTTP/1.1需要一个绝对URI作为»位置的参数:包括方案,主机名和绝对路径,
-ie.
头(“位置:http://$host.$uri”)'0')”
第一个关闭值块,第二个关闭调用
mysql\u query
@NicholasPickering:谢谢。我稍后要做准备的语句,我只是想得到这个优先级设置。另外,当我做更改时,加载页面时出错…“解析错误:语法错误,意外”;”在第17行的/home/u914842696/public_html/onlinegw/teams/create.php中,@user2203989在答案中使用更新的代码。感谢@NicholasPickering和@Blender的帮助!您在
标题('Location:../results.php?id=1')的末尾缺少了一个
谢谢。我没有注意到@sean