Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

TiagoWanderley

Erro SQL syntax!

Recommended Posts

Olá pessoal,

 

Não estou conseguindo inserir informações por meio de meu formulário, esta dando o seguinte erro:

 

 

ERRO NA PAGINA:

 

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 '030/2015'', ''002667/2015-43'', '111', '', '', 'DA', '', '', '', '', '', '', ''2' at line 1

 

PROGRAMAÇÃO:

<?php require_once("Connections/config.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_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO cad_processo (id, pro_memo, pro_numero, fonte1, fonte2, fonte3, dep_sigla_1, dep_sigla_2, dep_sigla_3, dep_sigla_4, dep_sigla_5, dep_sigla_6, dep_sigla_7, pro_data_rec, id_categoria, id_situacao, localizacao, pro_historico, pro_data_entrega, valor_estimado) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
                       GetSQLValueString($_POST['id'], "int"),
                       GetSQLValueString($_POST['pro_memo'], "text"),
                       GetSQLValueString($_POST['pro_numero'], "text"),
                       GetSQLValueString(isset($_POST['fonte1']) ? "true" : "", "defined","111",""),
                       GetSQLValueString(isset($_POST['fonte2']) ? "true" : "", "defined","184",""),
                       GetSQLValueString(isset($_POST['fonte3']) ? "true" : "", "defined","181",""),
                       GetSQLValueString(isset($_POST['dep_sigla_1']) ? "true" : "", "defined","DA",""),
                       GetSQLValueString(isset($_POST['dep_sigla_2']) ? "true" : "", "defined","DPSB",""),
                       GetSQLValueString(isset($_POST['dep_sigla_3']) ? "true" : "", "defined","DPSE",""),
                       GetSQLValueString(isset($_POST['dep_sigla_4']) ? "true" : "", "defined","DIMAPS",""),
                       GetSQLValueString(isset($_POST['dep_sigla_5']) ? "true" : "", "defined","DF",""),
                       GetSQLValueString(isset($_POST['dep_sigla_6']) ? "true" : "", "defined","DDQP",""),
                       GetSQLValueString(isset($_POST['dep_sigla_7']) ? "true" : "", "defined","DSA",""),
                       GetSQLValueString($_POST['pro_data_rec'], "text"),
                       GetSQLValueString($_POST['id_categoria'], "text"),
                       GetSQLValueString($_POST['id_situacao'], "text"),
                       GetSQLValueString($_POST['localizacao'], "text"),
                       GetSQLValueString($_POST['pro_historico'], "text"),
                       GetSQLValueString($_POST['pro_data_entrega'], "text"),
                       GetSQLValueString($_POST['valor_estimado'], "text"));

  mysql_select_db($database_config, $config);
  $Result1 = mysql_query($insertSQL, $config) or die(mysql_error());

  $insertGoTo = "enviado2.html";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

				mysql_select_db($database_config, $config);
				$query_situacao = "SELECT * FROM cad_situacao";
				$situacao = mysql_query($query_situacao, $config) or die(mysql_error());
				$row_situacao = mysql_fetch_assoc($situacao);
				$totalRows_situacao = mysql_num_rows($situacao);
				
				mysql_select_db($database_config, $config);
				$query_categoria = "SELECT * FROM cad_categoria";
				$categoria = mysql_query($query_categoria, $config) or die(mysql_error());
				$row_categoria = mysql_fetch_assoc($categoria);
				$totalRows_categoria = mysql_num_rows($categoria);
				
				mysql_select_db($database_config, $config);
				$query_localizacao = "SELECT * FROM cad_localizacao";
				$localizacao = mysql_query($query_localizacao, $config) or die(mysql_error());
				$row_localizacao = mysql_fetch_assoc($localizacao);
				$totalRows_localizacao = mysql_num_rows($localizacao);
?>

FORMULÁRIO:

<fieldset>
        <legend><font size="+2">Cadastro de Processo</font></legend>
        	<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
          <br />
          <table width="647" align="center">
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">N° do Memorando:</td>
              <td>
                  <input type="text" name="pro_memo" value="" size="32" />
                  <font size="-2" color="#FF0000">Ex.: (000/0000)</font></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">N° do Processo:</td>
              <td>
              	  <input type="text" name="pro_numero" value="" size="32" />
                  <font size="-2" color="#FF0000">Ex.: (000000/0000-00)</font>
              </td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Fonte(s) Pagadora(s):</td>
              <td>
              	  <input type="checkbox" name="fonte1" value="" />111
                  <input type="checkbox" name="fonte2" value="" />184
                  <input type="checkbox" name="fonte3" value="" />181
               </td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Departamento Solicitante:</td>
              <td>
              	  <input type="checkbox" name="dep_sigla_1" value="" />DA
                  <input type="checkbox" name="dep_sigla_2" value="" />DPSB
                  <input type="checkbox" name="dep_sigla_3" value="" />DPSE
                  <input type="checkbox" name="dep_sigla_4" value="" />DIMAPS
              </td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right"> </td>
              <td>
              	 <input type="checkbox" name="dep_sigla_5" value="" />DF
                 <input type="checkbox" name="dep_sigla_6" value="" />DDQP
                 <input type="checkbox" name="dep_sigla_7" value="" />DSA
              </td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Data do Recebimento do Processo:</td>
              <td>
              	<input type="text" name="pro_data_rec" value="" size="32" />
                <font size="-2" color="#FF0000"> Ex.: (dd/mm/aaaa)</font>
              </td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Categoria do Pedido:</td>
              <td>
              <select name="id_categoria">
                  <?php do {?>
                 	 <option value="<?php echo $row_categoria['categoria']?>" ><?php echo $row_categoria['categoria']?></option>
                  <?php } while ($row_categoria = mysql_fetch_assoc($categoria));?>
              </select>
              </td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Situação do Processo:</td>
              <td>
              <select name="id_situacao">
                  <?php do {?>
                  	<option value="<?php echo $row_situacao['situacao']?>" ><?php echo $row_situacao['situacao']?></option>
                  <?php } while ($row_situacao = mysql_fetch_assoc($situacao));?>
              </select>
              </td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Localização do Processo:</td>
              <td>
              <select name="localizacao">
                  <?php do { ?>
                  	<option value="<?php echo $row_localizacao['departamento']?>" ><?php echo $row_localizacao['departamento']?></option>
                  <?php } while ($row_localizacao = mysql_fetch_assoc($localizacao));?>
              </select>
              </td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right" valign="top">Histórico:</td>
              <td><textarea name="pro_historico" cols="50" rows="5"></textarea></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Data da Finalização em Compras:</td>
              <td><input type="text" name="pro_data_entrega" value="" size="32" />
                <font size="-2" color="#FF0000"> Ex.: (dd/mm/aaaa)</font></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Valor Estimado do Processo:</td>
              <td><input type="text" name="valor_estimado" value="" size="32" />
                <font size="-2" color="#FF0000"> Ex.: (R$ 0.000,00)</font></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right"> </td>
              <td><input name="inserir" type="submit" id="inserir" value="Inserir" />                <label>
                <input type="submit" name="apagar" id="apagar" value="Apagar dados" />
              </label></td>
            </tr>
          </table>
          <input type="hidden" name="id" value="" />
          <input type="hidden" name="MM_insert" value="form1" />
       </form>
	</fieldset>

ESTRUTURA BANCO DE DADOS:


CREATE TABLE IF NOT EXISTS `cad_processo` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `pro_memo` varchar(100) NOT NULL,
  `pro_numero` varchar(100) NOT NULL,
  `fonte1` varchar(10) NOT NULL,
  `fonte2` varchar(10) NOT NULL,
  `fonte3` varchar(10) NOT NULL,
  `dep_sigla_1` varchar(100) NOT NULL,
  `dep_sigla_2` varchar(10) NOT NULL,
  `dep_sigla_3` varchar(10) NOT NULL,
  `dep_sigla_4` varchar(10) NOT NULL,
  `dep_sigla_5` varchar(10) NOT NULL,
  `dep_sigla_6` varchar(10) NOT NULL,
  `dep_sigla_7` varchar(10) NOT NULL,
  `pro_data_rec` varchar(10) NOT NULL,
  `id_categoria` varchar(100) NOT NULL,
  `id_situacao` varchar(100) NOT NULL,
  `localizacao` varchar(50) NOT NULL,
  `pro_historico` text NOT NULL,
  `pro_data_entrega` varchar(10) DEFAULT NULL,
  `valor_estimado` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_categoria_3` (`id_categoria`),
  KEY `id_categoria` (`id_categoria`),
  KEY `id_categoria_2` (`id_categoria`),
  KEY `id_situacao` (`id_situacao`),
  KEY `id_categoria_4` (`id_categoria`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ;

Compartilhar este post


Link para o post
Compartilhar em outros sites

É aqui pra empresa que trabalho, agente usa planilha e to querendo transformar tudo em uma intranet.. A juda ai Mano! :mellow: Antes de fazer uma modificação colocando os "checkbox" funcionava bem direitinho a parte de cadastro, mas depois que fiz essa atualização esta dando esse erro.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Dê um echo em $insertSQL para exibir a query que está sendo executada. Só assim pra achar o erro com mais facilidade.

PS: funções mysql_* estão obsoletas desde o PHP 5.5 e serão removidas do PHP em breve. Prefira usar MySQLi ou PDO. Veja mais aqui: http://www.ultimatephp.com.br/php-por-que-nao-utilizar-funcoes-mysql

Compartilhar este post


Link para o post
Compartilhar em outros sites

Refiz tudo novamente e deu certo voltou a funcionar e com as atualizações que fiz. Em algum lugar devo ter apagado algo. Infelizmente não consegui achar o erro mais, por outro lado voltou a funcionar.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.