gpt4 book ai didi

php - 我找不到 SQL 和 PHP 语法错误

转载 作者:行者123 更新时间:2023-11-29 13:09:44 24 4
gpt4 key购买 nike

首先祝大家有美好的一天,抱歉,如果这个问题可能非常简单,但我对 php 的了解很少。

我在页面中收到此错误:

*您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行“WHERE compagni_id=NULL”附近使用的正确语法*

这是我的代码,它很长,所以我只把开始部分放在我认为可能出现错误的地方。我知道这肯定是一个非常愚蠢的错误,比如缺少逗号或类似的错误,但即使在一些 PHP 代码检查器网站上我也找不到任何东西。

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form_compagni")) {
$updateSQL = sprintf("UPDATE compagni SET av_compagni_numero=%s, av_compagni_tipo01=%s, av_livello_01=%s, av_nome01=%s, av_compagni_tipo02=%s, av_livello_02=%s, av_nome02=%s, anim_taglia01=%s, anim_tipo01=%s, anim_iniz01=%s, anim_velo01=%s, anim_pf01=%s, anim_ca01=%s, anim_ca_sprov01=%s, anim_ca_cont01=%s, anim_atta01=%s, anim_lotta01=%s, anim_spazi01=%s, anim_porta01=%s, anim_atsp01=%s, anim_quali01=%s, anim_temp01=%s, anim_rifl01=%s, anim_volo01=%s, anim_forz01=%s, anim_dest01=%s, anim_cost01=%s, anim_inte01=%s, anim_sagg01=%s, anim_cari01=%s, anim_abil01=%s, anim_tale01=%s, anim_coma01=%s, anim_ogge01=%s, cava_taglia01=%s, cava_tipo01=%s, cava_iniz01=%s, cava_velo01=%s, cava_pf01=%s, cava_ca01=%s, cava_ca_sprov01=%s, cava_ca_cont01=%s, cava_atta01=%s, cava_lotta01=%s, cava_spazi01=%s, cava_porta01=%s, cava_atsp01=%s, cava_quali01=%s, cava_temp01=%s, cava_rifl01=%s, cava_volo01=%s, cava_forz01=%s, cava_dest01=%s, cava_cost01=%s, cava_inte01=%s, cava_sagg01=%s, cava_cari01=%s, cava_abil01=%s, cava_tale01=%s, cava_ogge01=%s, comd_taglia01=%s, comd_tipo01=%s, comd_iniz01=%s, comd_velo01=%s, comd_pf01=%s, comd_ca01=%s, comd_ca_sprov01=%s, comd_ca_cont01=%s, comd_atta01=%s, comd_lotta01=%s, comd_spazi01=%s, comd_porta01=%s, comd_atsp01=%s, comd_quali01=%s, comd_temp01=%s, comd_rifl01=%s, comd_volo01=%s, comd_forz01=%s, comd_dest01=%s, comd_cost01=%s, comd_inte01=%s, comd_sagg01=%s, comd_cari01=%s, comd_abil01=%s, comd_tale01=%s, comd_coma01=%s, comd_ogge01=%s, comr_taglia01=%s, comr_tipo01=%s, comr_iniz01=%s, comr_velo01=%s, comr_pf01=%s, comr_ca01=%s, comr_ca_sprov01=%s, comr_ca_cont01=%s, comr_atta01=%s, comr_lotta01=%s, comr_spazi01=%s, comr_porta01=%s, comr_atsp01=%s, comr_quali01=%s, comr_temp01=%s, comr_rifl01=%s, comr_volo01=%s, comr_forz01=%s, comr_dest01=%s, comr_cost01=%s, comr_inte01=%s, comr_sagg01=%s, comr_cari01=%s, comr_abil01=%s, comr_tale01=%s, comr_coma01=%s, comr_ogge01=%s, fami_taglia01=%s, fami_tipo01=%s, fami_iniz01=%s, fami_velo01=%s, fami_pf01=%s, fami_ca01=%s, fami_ca_sprov01=%s, fami_ca_cont01=%s, fami_atta01=%s, fami_bab01=%s, fami_lotta01=%s, fami_spazi01=%s, fami_porta01=%s, fami_atsp01=%s, fami_quali01=%s, fami_temp01=%s, fami_rifl01=%s, fami_volo01=%s, fami_forz01=%s, fami_dest01=%s, fami_cost01=%s, fami_inte01=%s, fami_sagg01=%s, fami_cari01=%s, fami_abil01=%s, fami_tale01=%s, fami_ogge01=%s, greg_classe01=%s, greg_liv01=%s, greg_razza01=%s, greg_taglia01=%s, greg_iniz01=%s, greg_velo01=%s, greg_pf01=%s, greg_ca01=%s, greg_ca_sprov01=%s, greg_ca_cont01=%s, greg_atta01=%s, greg_bab01=%s, greg_lotta01=%s, greg_spazi01=%s, greg_porta01=%s, greg_atsp01=%s, greg_inca01=%s, greg_inca_classe01=%s, greg_inca_classe01_descr=%s, greg_quali01=%s, greg_temp01=%s, greg_rifl01=%s, greg_volo01=%s, greg_forz01=%s, greg_dest01=%s, greg_cost01=%s, greg_inte01=%s, greg_sagg01=%s, greg_cari01=%s, greg_abil01=%s, greg_tale01=%s, greg_ogge01=%s, greg_descr01=%s, anim_taglia02=%s, anim_tipo02=%s, anim_iniz02=%s, anim_velo02=%s, anim_pf02=%s, anim_ca02=%s, anim_ca_sprov02=%s, anim_ca_cont02=%s, anim_atta02=%s, anim_lotta02=%s, anim_spazi02=%s, anim_porta02=%s, anim_atsp02=%s, anim_quali02=%s, anim_temp02=%s, anim_rifl02=%s, anim_volo02=%s, anim_forz02=%s, anim_dest02=%s, anim_cost02=%s, anim_inte02=%s, anim_sagg02=%s, anim_cari02=%s, anim_abil02=%s, anim_tale02=%s, anim_coma02=%s, anim_ogge02=%s, cava_taglia02=%s, cava_tipo02=%s, cava_iniz02=%s, cava_velo02=%s, cava_pf02=%s, cava_ca02=%s, cava_ca_sprov02=%s, cava_ca_cont02=%s, cava_atta02=%s, cava_lotta02=%s, cava_spazi02=%s, cava_porta02=%s, cava_atsp02=%s, cava_quali02=%s, cava_temp02=%s, cava_rifl02=%s, cava_volo02=%s, cava_forz02=%s, cava_dest02=%s, cava_cost02=%s, cava_inte02=%s, cava_sagg02=%s, cava_cari02=%s, cava_abil02=%s, cava_tale02=%s, cava_ogge02=%s, comd_taglia02=%s, comd_tipo02=%s, comd_iniz02=%s, comd_velo02=%s, comd_pf02=%s, comd_ca02=%s, comd_ca_sprov02=%s, comd_ca_cont02=%s, comd_atta02=%s, comd_lotta02=%s, comd_spazi02=%s, comd_porta02=%s, comd_atsp02=%s, comd_quali02=%s, comd_temp02=%s, comd_rifl02=%s, comd_volo02=%s, comd_forz02=%s, comd_dest02=%s, comd_cost02=%s, comd_inte02=%s, comd_sagg02=%s, comd_cari02=%s, comd_abil02=%s, comd_tale02=%s, comd_coma02=%s, comd_ogge02=%s, comr_taglia02=%s, comr_tipo02=%s, comr_iniz02=%s, comr_velo02=%s, comr_pf02=%s, comr_ca02=%s, comr_ca_sprov02=%s, comr_ca_cont02=%s, comr_atta02=%s, comr_lotta02=%s, comr_spazi02=%s, comr_porta02=%s, comr_atsp02=%s, comr_quali02=%s, comr_temp02=%s, comr_rifl02=%s, comr_volo02=%s, comr_forz02=%s, comr_dest02=%s, comr_cost02=%s, comr_inte02=%s, comr_sagg02=%s, comr_cari02=%s, comr_abil02=%s, comr_tale02=%s, comr_coma02=%s, comr_ogge02=%s, fami_taglia02=%s, fami_tipo02=%s, fami_iniz02=%s, fami_velo02=%s, fami_pf02=%s, fami_ca02=%s, fami_ca_sprov02=%s, fami_ca_cont02=%s, fami_atta02=%s, fami_bab02=%s, fami_lotta02=%s, fami_spazi02=%s, fami_porta02=%s, fami_atsp02=%s, fami_quali02=%s, fami_temp02=%s, fami_rifl02=%s, fami_volo02=%s, fami_forz02=%s, fami_dest02=%s, fami_cost02=%s, fami_inte02=%s, fami_sagg02=%s, fami_cari02=%s, fami_abil02=%s, fami_tale02=%s, fami_ogge02=%s, greg_classe02=%s, greg_liv02=%s, greg_razza02=%s, greg_taglia02=%s, greg_iniz02=%s, greg_velo02=%s, greg_pf02=%s, greg_ca02=%s, greg_ca_sprov02=%s, greg_ca_cont02=%s, greg_atta02=%s, greg_bab02=%s, greg_lotta02=%s, greg_spazi02=%s, greg_porta02=%s, greg_atsp02=%s, greg_inca02=%s, greg_inca_classe02=%s, greg_inca_classe02_descr=%s, greg_quali02=%s, greg_temp02=%s, greg_rifl02=%s, greg_volo02=%s, greg_forz02=%s, greg_dest02=%s, greg_cost02=%s, greg_inte02=%s, greg_sagg02=%s, greg_cari02=%s, greg_abil02=%s, greg_tale02=%s, greg_ogge02=%s, greg_descr02 WHERE compagni_id=%s",
GetSQLValueString($_POST['av_compagni_numero'], "text"),
GetSQLValueString($_POST['av_compagni_tipo01'], "text"),

[...这里继续所有发布信息..]

GetSQLValueString($_POST['greg_ogge02'], "text"),
GetSQLValueString($_POST['greg_descr02'], "text"),
GetSQLValueString($_POST['compagni_id'], "int"));

mysql_select_db($database_Database, $Database);
$Result1 = mysql_query($updateSQL, $Database) or die(mysql_error());

$updateGoTo = "compagni.php?" . $row_compagni['compagni_id'] . "=" . $row_compagni['compagni_id'] . "";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

$colname_compagni = "1";
if (isset($_GET['compagni_id'])) {
$colname_compagni = $_GET['compagni_id'];
}
mysql_select_db($database_Database, $Database);
$query_compagni = sprintf("SELECT * FROM compagni WHERE compagni_id = %s", GetSQLValueString($colname_compagni, "int"));
$compagni = mysql_query($query_compagni, $Database) or die(mysql_error());
$row_compagni = mysql_fetch_assoc($compagni);
$totalRows_compagni = mysql_num_rows($compagni);

$colname_compagni = "1";
if (isset($_GET['compagni_id'])) {
$colname_compagni = $_GET['compagni_id'];
}
mysql_select_db($database_Database, $Database);
$query_compagni = sprintf("SELECT * FROM compagni WHERE compagni_id = %s", GetSQLValueString($colname_compagni, "int"));
$compagni = mysql_query($query_compagni, $Database) or die(mysql_error());
$row_compagni = mysql_fetch_assoc($compagni);
?>

我知道代码有点困惑,但我正在使用 Dreamweaver(不幸的是),而他正在编写 php 代码。

哪里出错了?

感谢您耐心阅读所有代码的建议!

最佳答案

追踪 mysql 错误的最佳方法是查看实际错误。在这种情况下:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行“WHERE compagni_id=NULL”附近使用的正确语法

因此,我们发现 WHERE ... 附近有一个语法错误,因此我们将查看紧邻字符串之前的内容。如果这对于具有多个联合或联接的长查询不明确,请尝试添加换行符并再次运行查询以获取行号。

因此,错误之前的查询部分是 greg_descr02

接下来要做的是look for what the syntax should be以及你实际拥有的东西。

UPDATE [LOW_PRIORITY] [IGNORE] table_reference
SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]

哦,我们看到在 WHERE 之前唯一应该出现的是列名,后跟等号,然后是表达式或 DEFAULT。您错过了等号和值。

希望这对您将来有所帮助。

Give a man a fish and he eats for a day, teach a man to fish and he will eat for the rest of his life.

关于php - 我找不到 SQL 和 PHP 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22251361/

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