punxgirl 0 Denunciar post Postado Maio 18, 2005 pessoal, eu estou tendo problemas na hora de atualizar um registro de produtos todos os outros s~ao atualizados normalmente menos o de fotos do _produto...eu gostaria que vcs me dessem uma luz de como fazer ele atualizar o registro caso a pessoa selecione uma foto diferente da que esta gravada no bd ou se ela n~ao escolher nenhuma deixar a que esta gravada...por que no meu caso eu uso o input tipo file que a pessoa procura nas pastas pela foto...mas no caso de atualizacao n~ao consigo fazer ele mostrar o arquivo ja gravado portanto ele fica vazio e ai se a pessoa nao escolhe nada...ele vai vazio...qdo deveria manter o ja gravado....deu pra entender...eu uso o copy pra mandar a foto pra uma pasta e gravo s'o o nome no bd... Compartilhar este post Link para o post Compartilhar em outros sites
punxgirl 0 Denunciar post Postado Maio 18, 2005 <?php require_once('../Connections/watches.php'); ?><?phpfunction 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 = $HTTP_SERVER_VARS['PHP_SELF'];if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];}//esse if eu inclui para verificar se a variavel do formulario de atualizacao esta vazia ou não, se estiver vazia mantém o dado gravado no bd no caso o nome da foto $valor=$HTTP_POST_VARS['foto_produto'];if ($valor = '') { $valor = $row_produtos['foto_produto'];} else { $valor = GetSQLValueString($HTTP_POST_VARS['foto_produto'], "text");} if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE produtos SET nome_produto=%s, descricao_produto=%s, foto_produto='$valor' WHERE id_produto=%s", GetSQLValueString($HTTP_POST_VARS['nome_produto'], "text"), GetSQLValueString($HTTP_POST_VARS['descricao_produto'], "text"), GetSQLValueString($valor, "text"), GetSQLValueString($HTTP_POST_VARS['id_produto'], "int")); copy ($foto_produto,"/home/francis/public_html/images/".$foto_produto_name); mysql_select_db($database_watches, $watches); $Result1 = mysql_query($updateSQL, $watches) or die(mysql_error()); $updateGoTo = "index.php"; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo));}$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];$maxRows_produtos = 20;$pageNum_produtos = 0;if (isset($HTTP_GET_VARS['pageNum_produtos'])) { $pageNum_produtos = $HTTP_GET_VARS['pageNum_produtos'];}$startRow_produtos = $pageNum_produtos * $maxRows_produtos;$colname_produtos = "1";if (isset($HTTP_GET_VARS['id'])) { $colname_produtos = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['id'] : addslashes($HTTP_GET_VARS['id']);}mysql_select_db($database_watches, $watches);$query_produtos = sprintf("SELECT * FROM produtos WHERE id_produto = %s", $colname_produtos);$query_limit_produtos = sprintf("%s LIMIT %d, %d", $query_produtos, $startRow_produtos, $maxRows_produtos);$produtos = mysql_query($query_limit_produtos, $watches) or die(mysql_error());$row_produtos = mysql_fetch_assoc($produtos);if (isset($HTTP_GET_VARS['totalRows_produtos'])) { $totalRows_produtos = $HTTP_GET_VARS['totalRows_produtos'];} else { $all_produtos = mysql_query($query_produtos); $totalRows_produtos = mysql_num_rows($all_produtos);}$totalPages_produtos = ceil($totalRows_produtos/$maxRows_produtos)-1;$queryString_produtos = "";if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) { $params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_produtos") == false && stristr($param, "totalRows_produtos") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_produtos = "&" . implode("&", $newParams); }}$queryString_produtos = sprintf("&totalRows_produtos=%d%s", $totalRows_produtos, $queryString_produtos);?><html><head><title>Painel de Controle - WATCHESNET</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><LINK href="../estilo.css" rel=stylesheet type=text/css></head><body bgcolor="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><table width="100%" height="521" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#666633" class="tit"> <tr> <td height="57" align="left" valign="middle" class="tit"><br> WACTHESNET - ATUALIZAÇÃO DE PRODUTO</td> </tr> </table> <br> <br> <br> <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1"> <table width="68%" height="121" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="50%" height="28" class="title">NOME DO PRODUTO</td> <td width="50%"> <input name="nome_produto" type="text" class="form" id="nome_produto" value="<?php echo $row_produtos['nome_produto']; ?>"> </td> </tr> <tr> <td height="32" class="title">DESCRIÇÃO DO PRODUTO</td> <td align="left"><div align="center"></div> <div align="left"> <input name="descricao_produto" type="text" class="form" id="descricao_produto" value="<?php echo $row_produtos['descricao_produto']; ?>"> </div> <div align="center"> </div> </td> </tr> <tr> <td height="31" class="title">FOTO DO PRODUTO</td> <td align="left" class="texto_maior"> <?php echo $row_produtos['foto_produto']; ?> <input name="foto_produto" type="file" class="form" id="foto_produto"> </td> </tr> <tr> <td height="6" class="texto_maior"> </td> <td align="left"><input name="Submit" type="submit" class="form" value="Atualizar"> </td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> <input name="id_produto" type="hidden" id="id_produto" value="<?php echo $row_produtos['id_produto']; ?>"> <input type="hidden" name="MM_update" value="form1"> </form> <br> <table width="50%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td class="links"><div align="center"><a href="index.php" target="_parent"><<Voltar</a></div> </td> </tr> </table></td> </tr></table></body></html><?phpmysql_free_result($produtos);?> Compartilhar este post Link para o post Compartilhar em outros sites