Jump to content


Photo

Upload De Imagem E Dados


  • Faça o login para participar
3 replies to this topic

#1 gersonab

gersonab

    Normal

  • Usuários
  • 113 posts
  • Sexo:Não informado

Posted 29/08/2008, 14:34

o código abaixo foi feito seguindo as istruções do curso do nosso amigo Leandro, no entanto esta dando erro .

<?php require_once(../Connections/connDB.php'); ?>
<?php include('../includes/class/W3_Image.class.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")) {
	$strKey = substr(md5( uniqid( microtime())), 0, 28);
  $insertSQL = sprintf("INSERT INTO cc_autos (intCatID, strNotTitle, strMarc, strAge, strNotText, strNotImage, strAgencia, strContato, strTel, strValor, intUsrID, strNotStatus, strNotHome) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
					   GetSQLValueString($_POST['intCatID'], "int"),
					   GetSQLValueString($_POST['strNotTitle'], "text"),
					   GetSQLValueString($_POST['strMarc'], "text"),
					   GetSQLValueString($_POST['strAge'], "text"),
					   GetSQLValueString($_POST['strNotText'], "text"),
					   GetSQLValueString($strKey , '.jpg', "text"),
					   GetSQLValueString($_POST['strAgencia'], "text"),
					   GetSQLValueString($_POST['strContato'], "text"),
					   GetSQLValueString($_POST['strTel'], "text"),
					   GetSQLValueString($_POST['strValor'], "text"),
					   GetSQLValueString($_POST['intUsrID'], "int"),
					   GetSQLValueString($_POST['strNotStatus'], "text"),
					   GetSQLValueString($_POST['strNotHome'], "text"));

  mysql_select_db($database_connDB, $connDB);
  $Result1 = mysql_query($insertSQL, $connDB) or die(mysql_error());
	$strImageTmp = $_FILES['strNotImage']['tmp_name'];
	$objImg = new W3_Image;
	$objImg->create( $strImageTmp, 75, 75, '../imagens/' . $strKey . '.thumb.jpg');
	$objImg->create( $strImageTmp, 640, 480, '../imagens/' . $strKey . '.jpg');
  $insertGoTo = "autos.php";
  if (isset($_SERVER['QUERY_STRING'])) {
	$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
	$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_connDB, $connDB);
$query_rsCategorias = "SELECT * FROM cc_autos_categorias ORDER BY strCatTitle ASC";
$rsCategorias = mysql_query($query_rsCategorias, $connDB) or die(mysql_error());
$row_rsCategorias = mysql_fetch_assoc($rsCategorias);
$totalRows_rsCategorias = mysql_num_rows($rsCategorias);

$colname_rsUsuarioLogado = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_rsUsuarioLogado = $_SESSION['MM_Username'];
}
mysql_select_db($database_connDB, $connDB);
$query_rsUsuarioLogado = sprintf("SELECT intUsrID FROM cc_usuarios WHERE strUsrEmail = %s", GetSQLValueString($colname_rsUsuarioLogado, "text"));
$rsUsuarioLogado = mysql_query($query_rsUsuarioLogado, $connDB) or die(mysql_error());
$row_rsUsuarioLogado = mysql_fetch_assoc($rsUsuarioLogado);
$totalRows_rsUsuarioLogado = mysql_num_rows($rsUsuarioLogado);
?>
<script type="text/javascript" src="../tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
	tinyMCE.init({
		mode : "textareas",
		theme : "simple"
	});
</script>

<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">Categoria :</td>
	  <td><select name="intCatID">
		<?php 
do {  
?>
		<option value="<?php echo $row_rsCategorias['intCatID']?>" ><?php echo $row_rsCategorias['strCatTitle']?></option>
		<?php
} while ($row_rsCategorias = mysql_fetch_assoc($rsCategorias));
?>
	  </select>
	  </td>
	</tr>
	<tr> </tr>
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right">Modelo :</td>
	  <td><input type="text" name="strNotTitle" value="" size="32" /></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right">Marca :</td>
	  <td><input type="text" name="strMarc" value="" size="32" /></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right">Ano :</td>
	  <td><input type="text" name="strAge" value="" size="32" /></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right" valign="top">Descrição</td>
	  <td><textarea name="strNotText" cols="50" rows="5"></textarea>
	  </td>
	</tr>
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right">Foto :</td>
	  <td><input name="strNotImage" type="file" size="32" /></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right">Agência :</td>
	  <td><input type="text" name="strAgencia" value="" size="32" /></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right">Contato :</td>
	  <td><input type="text" name="strContato" value="" size="32" /></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right">Tel :</td>
	  <td><input type="text" name="strTel" value="" size="32" /></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right">Valor :</td>
	  <td><input type="text" name="strValor" value="" size="32" /></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right">Estatus :</td>
	  <td><select name="strNotStatus">
		<option value="on" <?php if (!(strcmp("on", ""))) {echo "SELECTED";} ?>>Visível</option>
		<option value="off" <?php if (!(strcmp("off", ""))) {echo "SELECTED";} ?>>Oculto</option>
	  </select>
	  </td>
	</tr>
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right">Visível na Home ?</td>
	  <td><select name="strNotHome">
		<option value="yes" <?php if (!(strcmp("yes", ""))) {echo "SELECTED";} ?>>Sim</option>
		<option value="no" <?php if (!(strcmp("no", ""))) {echo "SELECTED";} ?>>Não</option>
	  </select>
	  </td>
	</tr>
	<tr valign="baseline">
	  <td nowrap="nowrap" align="right">&nbsp;</td>
	  <td><input type="submit" value="Insert record" /></td>
	</tr>
  </table>
  <input type="hidden" name="intUsrID" value="" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
<?
mysql_free_result($rsUsuarioLogado);

mysql_free_result($rsCategorias);
?>


o erro é este :
Unknown column 'b37f6a05aba30d7a3a4eab3e74de' in 'field list'

Ja li reli refiz e ainda não entendi ...

#2 Rustin

Rustin

    Parradise

  • Usuários
  • 578 posts
  • Sexo:Não informado

Posted 29/08/2008, 17:00

Nos campos que são char, varchar, text e similares tu precisa inserir os valores entre aspas, ou seja, '%s' ao invés de %s. Enquanto tu não fizer isso, o MySQL vai interpretar o valor que tu tá tentando inserir como uma coluna... Daí o erro.

Na verdade, revendo teu código, diria que o erro está aqui:
GetSQLValueString($strKey , '.jpg', "text"),

O certo seria:
GetSQLValueString($strKey . '.jpg', "text"),

Edição feita por: Rustin, 29/08/2008, 17:03.

"O fracasso não é o contrário do sucesso, mas sua fonte de inspiração". Thomas Edison

#3 gersonab

gersonab

    Normal

  • Usuários
  • 113 posts
  • Sexo:Não informado

Posted 29/08/2008, 19:46

realmente, foram correções que deixei passa, falta de atenção ....

agora o erro é

Warning: Cannot modify header information - headers already sent by (output started at /home/bolana/public_html/index.php:10) in /home/bolana/public_html/admin/auto-cadastrar.php on line 66

a linha 66 é

header(sprintf("Location: %s", $insertGoTo));

por via das dúvidas ja coloquei

header(sprintf("Location: '%s'", $insertGoTo));

manteve o erro .

outro detalhe, mesmo com este erro esta aocorrendo o cadastro , porém a imagem esta sendo visualizada de forma binaria , isto é , jbjnhjknjk43n5jk2nb5jknb.jpg .

#4 Dudu

Dudu

    Viva la vida

  • Usuários
  • 1437 posts
  • Sexo:Masculino
  • Localidade:Uberlândia - MG
  • Interesses:PHP

Posted 29/08/2008, 23:34

Pode ser que tenha uma saída html antes do Header.
Verifique isso.

Até mais ^_^

Fórum WMO - Equipe de Desenvolvimento / Banco de Dados - Moderador


Twitter: HostCheap





0 user(s) are reading this topic

0 membro(s), 0 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq