gpt4 book ai didi

php - 本地主机中的 SQL 语法错误

转载 作者:行者123 更新时间:2023-11-29 21:13:57 25 4
gpt4 key购买 nike

这是我的代码:

<?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

最佳答案

问题就出在这里

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

您不能在表名称或列上使用“' ”,请将其更改为

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

关于php - 本地主机中的 SQL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36120702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com