Roger40 0 Denunciar post Postado Outubro 2, 2009 Pessoal, Estou com um problemas no formulário PHP de envio de arquivos, porque não consigo enviá-lo e me mostra um erro assim: 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 ' '1149')' at line 1 O código fonte da página é este: admin.php <?php require_once('Connections/conn_uni.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $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")) { $arquivo = $_FILES["arquivo_usuario"]; $insertSQL = sprintf("INSERT INTO arquivos_clientes (arquivo_usuario, cliente_id, nome_cliente) VALUES ('$arquivo', %s, %s)", GetSQLValueString($_POST['arquivo_usuario'], "file"), GetSQLValueString($_POST['cliente_id'], "text"), GetSQLValueString($_POST['nome_cliente'], "text")); mysql_select_db($database_conn_uni, $conn_uni); $Result1 = mysql_query($insertSQL, $conn_uni) or die(mysql_error()); $insertGoTo = "admin.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_conn_uni, $conn_uni); $query_Rsarq = "SELECT * FROM arquivos_clientes"; $Rsarq = mysql_query($query_Rsarq, $conn_uni) or die(mysql_error()); $row_Rsarq = mysql_fetch_assoc($Rsarq); $totalRows_Rsarq = mysql_num_rows($Rsarq); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">Arquivo_usuario:</td> <td><input name="arquivo_usuario" type="file" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Cliente_id:</td> <td><input type="text" name="cliente_id" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Nome_cliente:</td> <td><input type="text" name="nome_cliente" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input type="submit" value="Insert record" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> <p> </p> </body> </html> <?php mysql_free_result($Rsarq); ?> Obrigado. Rogério Oliveira. Compartilhar este post Link para o post Compartilhar em outros sites
GabrielFerrari 41 Denunciar post Postado Outubro 2, 2009 Altere essa linha $query_Rsarq = "SELECT * FROM arquivos_clientes"; Para $query_Rsarq = "SELECT * FROM arquivos_clientes;"; Se não me engano tem () Se não der certo tente assim: $query_Rsarq = ("SELECT * FROM arquivos_clientes;"); Compartilhar este post Link para o post Compartilhar em outros sites
Roger40 0 Denunciar post Postado Outubro 2, 2009 Thelon. Fiz todas as alterações e o erro sempre é o mesmo abaixo:(já em português) Você tem um erro em sua sintaxe SQL; verifique o manual que corresponde ao seu servidor MySQL versão para o direito de utilizar sintaxe próximo ''1149') 'at line 1 Valeu! Compartilhar este post Link para o post Compartilhar em outros sites
GabrielFerrari 41 Denunciar post Postado Outubro 2, 2009 O erro está no SQL Nessa linha: $insertSQL = sprintf("INSERT INTO arquivos_clientes (arquivo_usuario, cliente_id, nome_cliente) VALUES ('$arquivo', %s, %s)" está sem o ; no final do INSERT INTO. Assim como o PHP os comando SQL também terminam com ; Verifique suas consultas. Se tiver dúvidas quanto a sintaxe pesquise aqui: http://www.w3schools.com/sql/default.asp Compartilhar este post Link para o post Compartilhar em outros sites
Roger40 0 Denunciar post Postado Outubro 5, 2009 Thelon. O que você me pediu eu fiz mas segue o erro que aparece:(já em português) Você tem um erro em sua sintaxe SQL; verifique o manual que corresponde ao seu servidor MySQL versão para o direito de utilizar sintaxe próximo '; arquivos_clientes (arquivo_usuario, cliente_id, nome_cliente) VALUES (Array,' at line 1 Obrigado. Compartilhar este post Link para o post Compartilhar em outros sites
GabrielFerrari 41 Denunciar post Postado Outubro 5, 2009 Poste o código correto depois das alterações. O erro mudou ... então tem que ver como está. Compartilhar este post Link para o post Compartilhar em outros sites
Roger40 0 Denunciar post Postado Outubro 5, 2009 Apenas acrescentei o ; após o INSERT INTO como você me falou. $insertSQL = sprintf("INSERT INTO; arquivos_clientes (arquivo_usuario, cliente_id, nome_cliente) VALUES ('$arquivo', %s, %s)", GetSQLValueString($_POST['arquivo_usuario'], "file"), GetSQLValueString($_POST['cliente_id'], "text"), GetSQLValueString($_POST['nome_cliente'], "text")); Se deixar o código original criado pelo Dreamweaver ele só envia o nome do arquivo ao banco de dados. Que é esse código abaixo. <?php require_once('Connections/conn_uni.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $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 arquivos_clientes (arquivo_usuario, cliente_id, nome_cliente) VALUES (%s, %s, %s)", GetSQLValueString($_POST['arquivo_usuario'], "text"), GetSQLValueString($_POST['cliente_id'], "text"), GetSQLValueString($_POST['nome_cliente'], "text")); mysql_select_db($database_conn_uni, $conn_uni); $Result1 = mysql_query($insertSQL, $conn_uni) or die(mysql_error()); $insertGoTo = "admin.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_conn_uni, $conn_uni); $query_Rsarq = ("SELECT * FROM arquivos_clientes"); $Rsarq = mysql_query($query_Rsarq, $conn_uni) or die(mysql_error()); $row_Rsarq = mysql_fetch_assoc($Rsarq); $totalRows_Rsarq = mysql_num_rows($Rsarq); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">Arquivo_usuario:</td> <td><input name="arquivo_usuario" type="file" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Cliente_id:</td> <td><input type="text" name="cliente_id" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Nome_cliente:</td> <td><input type="text" name="nome_cliente" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input type="submit" value="Insert record" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> <p> </p> </body> </html> <?php mysql_free_result($Rsarq); ?> Compartilhar este post Link para o post Compartilhar em outros sites
GabrielFerrari 41 Denunciar post Postado Outubro 5, 2009 Cara o ; é no final da instrução inser into e não depois do inser into No site que te passei lá em cima diz como deve ser usado e com alguns exemplos http://www.w3schools.com/sql/sql_insert.asp Compartilhar este post Link para o post Compartilhar em outros sites
Roger40 0 Denunciar post Postado Outubro 5, 2009 Thelon. Valeu, já funcionou. Já faço upload do arquivo para uma pasta do site. Só que gostaria de te pedir outra informação. Como crio um link de downloads para estes arquivos na lista de consulta criada pelo Dreamweaver, após o usuário efetuar logon para a lista de arquivos dele? Ai vai a página da listagem ( consulta ao Banco de dados ): lista.php <?php require_once('Connections/ConnLocal.php'); ?> <?php //initialize the session if (!isset($_SESSION)) { session_start(); } // ** Logout the current user. ** $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true"; if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){ $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){ //to fully log out a visitor we need to clear the session varialbles $_SESSION['MM_Username'] = NULL; $_SESSION['MM_UserGroup'] = NULL; $_SESSION['PrevUrl'] = NULL; unset($_SESSION['MM_Username']); unset($_SESSION['MM_UserGroup']); unset($_SESSION['PrevUrl']); $logoutGoTo = "login.php"; if ($logoutGoTo) { header("Location: $logoutGoTo"); exit; } } ?> <?php if (!isset($_SESSION)) { session_start(); } $MM_authorizedUsers = ""; $MM_donotCheckaccess = "true"; // *** Restrict Access To Page: Grant or deny access to this page function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { // For security, start by assuming the visitor is NOT authorized. $isValid = False; // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. // Therefore, we know that a user is NOT logged in if that Session variable is blank. if (!empty($UserName)) { // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. // Parse the strings into arrays. $arrUsers = Explode(",", $strUsers); $arrGroups = Explode(",", $strGroups); if (in_array($UserName, $arrUsers)) { $isValid = true; } // Or, you may restrict access to only certain users based on their username. if (in_array($UserGroup, $arrGroups)) { $isValid = true; } if (($strUsers == "") && true) { $isValid = true; } } return $isValid; } $MM_restrictGoTo = "login.php"; if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { $MM_qsChar = "?"; $MM_referrer = $_SERVER['PHP_SELF']; if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) $MM_referrer .= "?" . $QUERY_STRING; $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); exit; } ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $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; } } $maxRows_list = 10; $pageNum_list = 0; if (isset($_GET['pageNum_list'])) { $pageNum_list = $_GET['pageNum_list']; } $startRow_list = $pageNum_list * $maxRows_list; $colname_list = "-1"; if (isset($_SESSION['MM_Username'])) { $colname_list = $_SESSION['MM_Username']; } mysql_select_db($database_ConnLocal, $ConnLocal); $query_list = sprintf("SELECT * FROM upload WHERE id_arquivo = %s", GetSQLValueString($colname_list, "int")); $query_limit_list = sprintf("%s LIMIT %d, %d", $query_list, $startRow_list, $maxRows_list); $list = mysql_query($query_limit_list, $ConnLocal) or die(mysql_error()); $row_list = mysql_fetch_assoc($list); if (isset($_GET['totalRows_list'])) { $totalRows_list = $_GET['totalRows_list']; } else { $all_list = mysql_query($query_list); $totalRows_list = mysql_num_rows($all_list); } $totalPages_list = ceil($totalRows_list/$maxRows_list)-1; mysql_select_db($database_ConnLocal, $ConnLocal); $query_Usuarq = "SELECT * FROM usuarios"; $Usuarq = mysql_query($query_Usuarq, $ConnLocal) or die(mysql_error()); $row_Usuarq = mysql_fetch_assoc($Usuarq); $totalRows_Usuarq = mysql_num_rows($Usuarq); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <p>Olá, <?php echo $row_Usuarq['nome']; ?> seja bem vindo!</p> <p> </p> <p><a href="<?php echo $logoutAction ?>">Sair</a></p> <table border="0" cellpadding="2" cellspacing="3"> <tr> <td bgcolor="#999999">id</td> <td bgcolor="#999999">id_arquivo</td> <td bgcolor="#999999">titulo</td> <td bgcolor="#999999">texto</td> <td bgcolor="#999999">foto</td> </tr> <?php do { ?> <tr> <td><?php echo $row_list['id']; ?></td> <td><?php echo $row_list['id_arquivo']; ?></td> <td><?php echo $row_list['titulo']; ?></td> <td><?php echo $row_list['texto']; ?></td> <td><?php echo $row_list['foto']; ?></td> </tr> <?php } while ($row_list = mysql_fetch_assoc($list)); ?> </table> </body> </html> <?php mysql_free_result($list); mysql_free_result($Usuarq); ?> Quando abre essa consulta, só aparece os nomes dos arquivos que foram feitos uploads para o sistema.Grato. Rogério. Compartilhar este post Link para o post Compartilhar em outros sites
GabrielFerrari 41 Denunciar post Postado Outubro 5, 2009 Pega a variavel que você tem o nome do arquivo que subiu e cria um echo na págian depois do upload: echo "http://www.seusite.com.br/suapasta/" $variavel; Acho que seja algo assim. Compartilhar este post Link para o post Compartilhar em outros sites
Roger40 0 Denunciar post Postado Outubro 5, 2009 Thelon. Desculpa me explica melhor sobre pegar a variável do nome do arquivo? Abraço. Rogério Oliveira. Compartilhar este post Link para o post Compartilhar em outros sites
GabrielFerrari 41 Denunciar post Postado Outubro 5, 2009 $arquivo Acho que é essa variável que ta pegando. Compartilhar este post Link para o post Compartilhar em outros sites
Roger40 0 Denunciar post Postado Outubro 6, 2009 Thelon. Eu crio o link com o comando que você me enviou e não consigo exito porque não entendi onde exatamente inserir esse comando na página listar.php para funcionar. Obs: Preciso deixar esse link entre <?php ?> para funcionar? Grato Rogério Compartilhar este post Link para o post Compartilhar em outros sites
GabrielFerrari 41 Denunciar post Postado Outubro 6, 2009 Cara vou tentar explicar melhor. Sou ruim nisso. rs Assim quando você vai fazer o upload você tem um variável que pega o nome do arquivo do cara para poder upar. Você vai usar essa variável para gerar o link. Que no caso é $arquivo pelo que vi no código. Então para mostrar você vai usar uma função do PHP chamada echo ela simplesmente mostra alguma coisa na página. Vamos a um exemplo <?php echo "Thelon é gostoso" ?> Thelon é gostoso é uma verdade string (texto) por isso ela está entre " "(aspas) Agora vamos supor que você queira mostrar apenas o valor de uma variável <?php $T = "E bonito"; ?> O echo ficaria <?php echo $T; ?> O $T não precisa estar entre aspas pois já foi colocado lá na declaração do valor dela. Então se você juntar tudo fica <?php echo "Thelon é gostoso " $T; ?> Isso vai mostrar: Thelon é gostoso E bonito O mesmo acontece com o link http://www.seusite.com.br/suapasta/ -> Vai ser um texto fixo então é uma string <?php echo "http://www.seusite.com.br/suapasta/";'>http://www.seusite.com.br/suapasta/"; ?> Vai fazer mostrar: http://www.seusite.com.br/suapasta/ Como você quer para download Então temos que pegar o nome do arquivo também para gerar o link E o nome do arquivo está na variável $arquivo Então para mostrar tudo fica: <?php echo "http://www.seusite.com.br/suapasta/" $arquivo; ?> Qualquer problema é só postar :) Compartilhar este post Link para o post Compartilhar em outros sites