SQL和PHP语法中的错误,我找不到

时间:2014-03-07 13:27:08

标签: php mysql

首先,大家好日子,如果这个问题非常简单,我很抱歉,但我对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代码。

错误在哪里?

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

2 个答案:

答案 0 :(得分:1)

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

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE compagni_id=NULL' at line 1

因此,我们发现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。你错过了等号和价值。

我希望将来可以帮到你。

  

给一个人一条鱼,他吃了一天,教一个人钓鱼,他将在他的余生中吃。

答案 1 :(得分:0)

您没有为greg_descr02设置值。改变

greg_descr02 WHERE compagni_id=%s

greg_descr02=%s  WHERE compagni_id=%s