localhost中的SQL语法错误

时间:2016-03-20 23:01:14

标签: php mysql

这是我的代码:

<?php
require_once $_SERVER["DOCUMENT_ROOT"] . '/Lol/inc/head.php';

$name = $_POST['name'];

// I think that error is about this next line, but i cant find it

$query = "SELECT * FROM 'heroes' WHERE 'name' = '$name'";
$run =  mysql_query($query);
$row = mysql_fetch_array($run) or die(mysql_error()); 
$id = $row['id'];
$name = $row['name'];
$role = $row['role'];
$srole = $row['srole'];
$atack = $row['atack'];
$health = $row['health'];
$ability = $row['ability'];
$difficulty = $row['difficulty']; 


?>



Name: <?php echo $name; ?><br>
Role: <?php echo $role;?><br>
Secondary Role: <?php echo $srole;?> <br>
Atack: <?php echo $atack;?>/100<br>
Health: <?php echo $health;?>/100<br>
Ability: <?php echo $ability;?>/100<br>
Difficulty: <?php echo $difficulty;?>/100<br>

我在phpMyAdmin中创建了表格

这就是显示的内容 - 我在XAMPP中本地运行。

My website error

1 个答案:

答案 0 :(得分:0)

问题来自这里

$query = "SELECT * FROM 'heroes' WHERE 'name' = '$name'";

您不能在表名上使用“'”,也不能将其更改为

$query = "SELECT * FROM `heroes` WHERE `name` = '$name'";