Ir para conteúdo
Fórum Script Brasil
  • 0

Problema Ao Enviar Dados Para O Banco


caiognr

Pergunta

Boa tarde pessoal,

Eu criei um sistema que envia um arquivo para uma pasta no servidor e nome para o banco de dados. Porém eu queria saber como eu faço para mandar junto com o nome da foto o caminha físico, num único campo.

Segue o código:

<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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["Foto"];
$arquivo_nome = $arquivo["name"];
$endereco = "c:\inetpub\wwwroot\perfilimoveisonline\dados";
$tudo = $endereco + $arquivo_nome; 
  $insertSQL = sprintf("INSERT INTO imoveis (codneg, cod_tipo, local_cod, Área, Condomínio, Cidade, Bairro, Dormitórios, Valor, Detalhes, foto) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '$arquivo_nome')",
                       GetSQLValueString($_POST['codneg'], "int"),
                       GetSQLValueString($_POST['cod_tipo'], "int"),
                       GetSQLValueString($_POST['local_cod'], "int"),
                       GetSQLValueString($_POST['Área'], "int"),
                       GetSQLValueString($_POST['Condomínio'], "text"),
                       GetSQLValueString($_POST['Cidade'], "text"),
                       GetSQLValueString($_POST['Bairro'], "text"),
                       GetSQLValueString($_POST['Dormitórios'], "int"),
                       GetSQLValueString($_POST['Valor'], "double"),
                       GetSQLValueString($_POST['Detalhes'], "text"));
                      
set_time_limit(0);
$diretorio = "c:\inetpub\wwwroot\perfilimoveisonline\dados";
$id_arquivo = "foto";
$nome_arquivo = $_FILES[$id_arquivo]["name"];
$arquivo_temporario = $_FILES[$id_arquivo]["tmp_name"];
move_uploaded_file($arquivo_temporario, "$diretorio/$nome_arquivo");
                       

  mysql_select_db($database_conexao, $conexao);
  $Result1 = mysql_query($insertSQL, $conexao) or die(mysql_error());

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

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152k
    • Posts
      651,7k
×
×
  • Criar Novo...