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

Ajuda Urgente Com Upload De Arquivo


ronaldosdb

Pergunta

galera...to tentando fazer isso seguindo o tutorial do marcelo oliveira

alguém sabe onde esta o erro?

Notice: Undefined variable: foto_name in c:\arquivos de programas\easyphp1-8\www\insert_noticia.php on line 34

Notice: Undefined variable: foto in c:\arquivos de programas\easyphp1-8\www\insert_noticia.php on line 41

Notice: Undefined variable: foto_name in c:\arquivos de programas\easyphp1-8\www\insert_noticia.php on line 41

Warning: Cannot modify header information - headers already sent by (output started at c:\arquivos de programas\easyphp1-8\www\insert_noticia.php:34) in c:\arquivos de programas\easyphp1-8\www\insert_noticia.php on line 51

arquivo inserir.php

<?php require_once('Connections/ronaldo.php'); ?>
<?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")) {
  $insertSQL = sprintf("INSERT INTO noticias (id_noticia, titulo, corpo, foto, autor) VALUES (%s, %s, %s,'$foto_name', %s)",
                       GetSQLValueString($_POST['id_noticia'], "int"),
                       GetSQLValueString($_POST['titulo'], "text"),
                       GetSQLValueString($_POST['corpo'], "text"),
                       GetSQLValueString($_POST['foto'], "text"),
                       GetSQLValueString($_POST['autor'], "text"));

copy ($foto,"images/".$foto_name);

  mysql_select_db($database_ronaldo, $ronaldo);
  $Result1 = mysql_query($insertSQL, $ronaldo) or die(mysql_error());

  $insertGoTo = "/inserted_noticia.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Inser&ccedil;&atilde;o de Not&iacute;cias</title>
<link href="/css/noticia.css" rel="stylesheet" type="text/css">
</head>

<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <table align="center" class="tabela">
    <tr valign="baseline" class="noticia">
      <td nowrap align="right">Titulo:</td>
      <td><input type="text" name="titulo" value="" size="32"></td>
    </tr>
    <tr valign="baseline" class="noticia">
      <td nowrap align="right">Corpo:</td>
      <td><textarea name="corpo" cols="80" rows="30"></textarea></td>
    </tr>
    <tr valign="baseline" class="noticia">
      <td nowrap align="right">Foto:</td>
      <td><input name="foto" type="file" lang="pt" size="32"></td>
    </tr>
    <tr valign="baseline" class="noticia">
      <td nowrap align="right">Autor:</td>
      <td><input type="text" name="autor" value="" size="32"></td>
    </tr>
    <tr valign="baseline" class="noticia">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Cadastrar"></td>
    </tr>
  </table>
  <input type="hidden" name="id_noticia" value="">
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
</body>
</html>

Link para o comentário
Compartilhar em outros sites

17 respostass a esta questão

Posts Recomendados

  • 0

Deividy

O tutorial está aí, eu gostaria de fazer exatamente isso.....

http://www.dwmx.com.br/download/tutoriais_..._db_com_PHP.zip

Se conseguir achar o erro me da um toque....

Se voce perceber, estou cadastrando uma noticia com os campos titulo, corpo, foto, autor....

O campo id está como hidden, portanto o usuario não ve...

Acho que o problema está sendo com o campo foto...

Enfim, se você souber fazer o do arquivo eu implemento

Valeu

Ronaldo

Link para o comentário
Compartilhar em outros sites

  • 0

na linha do <form> coloca o q tá em vermelho

<form method="post" name="form1" action="<?php echo $editFormAction; ?>" enctype='multipart/form-data'>

e na função copy() faz assim

copy ($_FILES["foto"]["tmp_name"],"images/".$_FILES["foto"]["name"]);

vê se funciona, qualquer coisa posta ai

Link para o comentário
Compartilhar em outros sites

  • 0

ta dando esse erro:

Notice: Undefined variable: imagem in c:\arquivos de programas\easyphp1-8\www\insere.php on line 34

Notice: Undefined index: imagem in c:\arquivos de programas\easyphp1-8\www\insere.php on line 39

Warning: Cannot modify header information - headers already sent by (output started at c:\arquivos de programas\easyphp1-8\www\insere.php:34) in c:\arquivos de programas\easyphp1-8\www\insere.php on line 49
Referente a essa linha 34
  $insertSQL = sprintf("INSERT INTO noticias2 (codigo, manchete, autor, noticia, imagem) VALUES (%s, %s, %s, %s, '$imagem')",
39
 GetSQLValueString($_POST['imagem'], "text"));
49
header(sprintf("Location: %s", $insertGoTo));
eis o codigo:
<?php require_once('Connections/ronaldo.php'); ?>
<?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")) {
  $insertSQL = sprintf("INSERT INTO noticias2 (codigo, manchete, autor, noticia, imagem) VALUES (%s, %s, %s, %s, '$imagem')",
                       GetSQLValueString($_POST['codigo'], "int"),
                       GetSQLValueString($_POST['manchete'], "text"),
                       GetSQLValueString($_POST['autor'], "text"),
                       GetSQLValueString($_POST['noticia'], "text"),
                       GetSQLValueString($_POST['imagem'], "text"));
copy ($_FILES["imagem"]["tmp_name"],"imagens/".$_FILES["imagem"]["name"]);
  mysql_select_db($database_ronaldo, $ronaldo);
  $Result1 = mysql_query($insertSQL, $ronaldo) or die(mysql_error());

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

<form method="post" name="form1" action="<?php echo $editFormAction; ?>" enctype='multipart/form-data'>

  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Manchete:</td>
      <td><input type="text" name="manchete" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Autor:</td>
      <td><input type="text" name="autor" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Noticia:</td>
      <td><textarea name="noticia" cols="80" rows="35"></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Imagem:</td>
      <td><input name="imagem" type="file" lang="pt" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Inserir Not&iacute;cia"></td>
    </tr>
  </table>
  <input type="hidden" name="codigo" value="">
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>

Link para o comentário
Compartilhar em outros sites

  • 0

segue o mesmo erro, olha o codigo ai

<?php require_once('Connections/ronaldo.php'); ?>
<?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")) {
  $insertSQL = sprintf("INSERT INTO noticias2 (codigo, manchete, autor, noticia, imagem) VALUES (%s, %s, %s, %s, 'imagem')",
                       GetSQLValueString($_POST['codigo'], "int"),
                       GetSQLValueString($_POST['manchete'], "text"),
                       GetSQLValueString($_POST['autor'], "text"),
                       GetSQLValueString($_POST['noticia'], "text"),
                       GetSQLValueString($_POST['imagem'], "text"));
copy ($_FILES["imagem"]["tmp_name"],"imagens/".$_FILES["imagem"]["name"]
  mysql_select_db($database_ronaldo, $ronaldo);
  $Result1 = mysql_query($insertSQL, $ronaldo) or die(mysql_error());

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

<form method="post" name="form1" action="<?php echo $editFormAction; ?>" enctype='multipart/form-data'>

  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Manchete:</td>
      <td><input type="text" name="manchete" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Autor:</td>
      <td><input type="text" name="autor" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Noticia:</td>
      <td><textarea name="noticia" cols="80" rows="35"></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Imagem:</td>
      <td><input name="imagem" type="file" lang="pt" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Inserir Not&iacute;cia"></td>
    </tr>
  </table>
  <input type="hidden" name="codigo" value="">
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>

Link para o comentário
Compartilhar em outros sites

  • 0

Ta gravando armazenando no diretorio corretamente mantendo o nome do arquivo mas não ta gravando no bd, tem ideia do que seja:

Erro

Notice: Undefined variable: imagem in c:\arquivos de programas\easyphp1-8\www\insere.php on line 34

Notice: Array to string conversion in c:\arquivos de programas\easyphp1-8\www\insere.php on line 5

Warning: Cannot modify header information - headers already sent by (output started at c:\arquivos de programas\easyphp1-8\www\insere.php:34) in c:\arquivos de programas\easyphp1-8\www\insere.php on line 48
insere.php
<?php require_once('Connections/ronaldo.php'); ?>
<?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")) {
 $insertSQL = sprintf("INSERT INTO noticias2 (codigo, manchete, autor, noticia, imagem) VALUES (%s, %s, %s, %s, '$imagem')",
                      GetSQLValueString($_POST['codigo'], "int"),
                      GetSQLValueString($_POST['manchete'], "text"),
                      GetSQLValueString($_POST['autor'], "text"),
                      GetSQLValueString($_POST['noticia'], "text"),
                      GetSQLValueString($_FILES['imagem'], "text"));
 mysql_select_db($database_ronaldo, $ronaldo);
 $Result1 = mysql_query($insertSQL, $ronaldo) or die(mysql_error());
copy ($_FILES["imagem"]["tmp_name"],"imagens/".$_FILES["imagem"]["name"]);
 $insertGoTo = "ok.html";
 if (isset($_SERVER['QUERY_STRING'])) {
   $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
   $insertGoTo .= $_SERVER['QUERY_STRING'];
 }
 header(sprintf("Location: %s", $insertGoTo));
}
?>

<form method="post" name="form1" action="<?php echo $editFormAction; ?>" enctype='multipart/form-data'>

 <table align="center">
   <tr valign="baseline">
     <td nowrap align="right">Manchete:</td>
     <td><input type="text" name="manchete" value="" size="32"></td>
   </tr>
   <tr valign="baseline">
     <td nowrap align="right">Autor:</td>
     <td><input type="text" name="autor" value="" size="32"></td>
   </tr>
   <tr valign="baseline">
     <td nowrap align="right">Noticia:</td>
     <td><textarea name="noticia" cols="80" rows="35"></textarea></td>
   </tr>
   <tr valign="baseline">
     <td nowrap align="right">Imagem:</td>
     <td><input name="imagem" type="file" lang="pt" size="32"></td>
   </tr>
   <tr valign="baseline">
     <td nowrap align="right">&nbsp;</td>
     <td><input type="submit" value="Inserir Not&iacute;cia"></td>
   </tr>
 </table>
 <input type="hidden" name="codigo" value="">
 <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>

Link para o comentário
Compartilhar em outros sites

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
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...