[Resolvido] problemas com o insert
Pessoal!
Sou novo no dreamweaver e php. Consegui um tutorial sobre inserir registro em banco de dados usando o dreamweaver. Ta funcionando bem, só que todos s campos estão obrigatórios e precisava deixar alguns com preenchimento opcional (em branco) mas não estou conseguindo achar onde fazer as modificações.
Segue o codigo para analise e se você puderem me ajudar.
[ ]ss
CODE
<?php require_once('../Connections/conexao_imoveis.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 imoveis (cod, categoria, bairro, endereco, complemento, valor, condominio, quartos, suites, areatotal, garagem, descricao, observacao, destaque) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['cod'], "text"),
GetSQLValueString($_POST['categoria'], "text"),
GetSQLValueString($_POST['bairro'], "text"),
GetSQLValueString($_POST['endereco'], "text"),
GetSQLValueString($_POST['complemento'], "text"),
GetSQLValueString($_POST['valor'], "text"),
GetSQLValueString($_POST['condominio'], "text"),
GetSQLValueString($_POST['quartos'], "text"),
GetSQLValueString($_POST['suites'], "text"),
GetSQLValueString($_POST['areatotal'], "text"),
GetSQLValueString($_POST['garagem'], "text"),
GetSQLValueString($_POST['descricao'], "text"),
GetSQLValueString($_POST['observacao'], "text"),
GetSQLValueString(isset($_POST['destaque']) ? "true" : "", "defined","'Y'","'N'"));
mysql_select_db($database_conexao_imoveis, $conexao_imoveis);
$Result1 = mysql_query($insertSQL, $conexao_imoveis) or die(mysql_error());
$insertGoTo = "sucesso_inclusao.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_conexao_imoveis, $conexao_imoveis);
$query_seleciona_bairro = "SELECT bairro.bairro FROM bairro";
$seleciona_bairro = mysql_query($query_seleciona_bairro, $conexao_imoveis) or die(mysql_error());
$row_seleciona_bairro = mysql_fetch_assoc($seleciona_bairro);
$totalRows_seleciona_bairro = mysql_num_rows($seleciona_bairro);
mysql_select_db($database_conexao_imoveis, $conexao_imoveis);
$query_seleciona_categoria = "SELECT categoria.categoria FROM categoria";
$seleciona_categoria = mysql_query($query_seleciona_categoria, $conexao_imoveis) or die(mysql_error());
$row_seleciona_categoria = mysql_fetch_assoc($seleciona_categoria);
$totalRows_seleciona_categoria = mysql_num_rows($seleciona_categoria);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Inserir imóvel</title>
<style type="text/css">
<!--
.style3 {font-size: 12px}
a{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #333333;
text-decoration: none;
}
a:hover{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #FFFFFF;
text-decoration: none;
background-color: #CC0000;
}
-->
</style>
</head>
<body>
<? include "cabecalho.php";?>
<em><strong>Cadastro de Imóveis</strong></em>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="left">
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Cod:</td>
<td bgcolor="#E3EAF0"><input type="text" name="cod" value="" size="32">
<br />
<span class="style3">Digite o código do imóvel</span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Categoria:</td>
<td bgcolor="#E3EAF0"><select name="categoria">
<?php
do {
?>
<option value="<?php echo $row_seleciona_categoria['categoria']?>" ><?php echo $row_seleciona_categoria['categoria']?></option>
<?php
} while ($row_seleciona_categoria = mysql_fetch_assoc($seleciona_categoria));
?>
</select></td>
<tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Bairro:</td>
<td bgcolor="#E3EAF0"><select name="bairro">
<?php
do {
?>
<option value="<?php echo $row_seleciona_bairro['bairro']?>" ><?php echo $row_seleciona_bairro['bairro']?></option>
<?php
} while ($row_seleciona_bairro = mysql_fetch_assoc($seleciona_bairro));
?>
</select></td>
<tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Endereco:</td>
<td bgcolor="#E3EAF0"><input name="endereco" type="text" value="" size="32" maxlength="60">
<br />
<span class="style3">Rua x, 00</span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Complemento:</td>
<td bgcolor="#E3EAF0"><input type="text" name="complemento" value="" size="32">
<br />
<span class="style3">Ex. apto 000</span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Valor:</td>
<td bgcolor="#E3EAF0"><input type="text" name="valor" value="" size="32">
<br />
<span class="style3">Digite o valor do alugue(Ex.: 1.000,00)</span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Condominio:</td>
<td bgcolor="#E3EAF0"><input type="text" name="condominio" value="" size="32">
<br />
<span class="style3">Se existe condominio digite o valor (Ex. 00,00) </span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Quartos:</td>
<td bgcolor="#E3EAF0"><input type="text" name="quartos" value="" size="32">
<br />
<span class="style3">Digite a quantidade de quartos </span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Suítes:</td>
<td bgcolor="#E3EAF0"><input type="text" name="suites" value="" size="32">
<br />
<span class="style3">Digite a quantidade de suites </span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Área total:</td>
<td bgcolor="#E3EAF0"><input type="text" name="areatotal" value="" size="32">
<br />
<span class="style3">Digite a área total do imóvel (Ex.: 55 m² ) </span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Garagem:</td>
<td bgcolor="#E3EAF0"><input type="text" name="garagem" value="" size="32">
<br />
<span class="style3">Se existe garagem digite o número de <br />
vagas se não digite <em>não</em> </span></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Descricao:</td>
<td bgcolor="#E3EAF0"><span class="style3">Digite abaixo uma breve descrição do imóvel </span><br />
<textarea name="descricao" cols="32"></textarea></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Observacao:</td>
<td bgcolor="#E3EAF0"><span class="style3">Se desejar faça aqui algumas observações </span><br />
<textarea name="observacao" cols="32"></textarea></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap bgcolor="#F7F7F7">Destaque:</td>
<td bgcolor="#E3EAF0"><input type="checkbox" name="destaque" value="" >
<span class="style3">(Selecione se deseja inclui-lo na página inicial)</span> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Cadastrar imóvel"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
<?php
mysql_free_result($seleciona_bairro);
mysql_free_result($seleciona_categoria);
?>Discussão (2)
Carregando comentários...