Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá, gostaria de saber ,como posso fazer para que após o envio de um formulário , ele retorne um mensagem em forma de caixa de dialogo e atualize a página, vejo isso em vários lugares,mas não tenho noção de como faço rsrsrs, Alguém pode me ajudar ?
Em qual parte ? '-' Desculpe, estou meio confuso ;s
<?php require_once('Connections/host1nger.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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"] == "form")) {
$insertSQL = sprintf("INSERT INTO contato_formularios (nome, email, telefone, texto) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['nome'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['telefone'], "text"),
GetSQLValueString($_POST['comments'], "text"));
mysql_select_db($database_host1nger, $host1nger);
$Result1 = mysql_query($insertSQL, $host1nger) or die(mysql_error());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="CSS/maxsuel-11-02.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="fb-root"></div>
<section id="cabecalho">
</section>
<div class="container">
<div class="sidebar1">
</div>
<div class="content">
<div id="corpp">
<div class="fatia3">
<img src="img/entrecontato.fw.png" width="242" height="35" />
<form name="form" action="<?php echo $editFormAction; ?>" method="POST">
<div> Preencha o formulário abaixo com suas dúvidas ou sugestões. </div>
<div>Seu nome :</div>
<div><input name="nome" type="text" size="40" /></div>
<div>Seu E-mail :</div>
<div><input name="email" type="text" id="email" size="40" /></div>
<div>Seu telefone :</div>
<div><input name="telefone" type="text" size="40" /></div>
<div>Comentários :</div>
<div>
<textarea name="comments" cols="55" rows="10"></textarea>
</div>
<div style="float:right;">
<input type="submit" name="enviar" id="enviar" value="Enviar" />
</div>
<input type="hidden" name="MM_insert" value="form" />
</form>
</div>
<div></div>
</div>
<!-- end .container -->
</div>
<section id="rodapé"></section>
</body>
</html>Basta você estudar o script que você "programou" no dreamweaver e verificar os condicionais...
>
Em qual parte ? '-' Desculpe, estou meio confuso ;s
<?php require_once('Connections/host1nger.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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"] == "form")) {
$insertSQL = sprintf("INSERT INTO contato_formularios (nome, email, telefone, texto) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['nome'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['telefone'], "text"),
GetSQLValueString($_POST['comments'], "text"));
mysql_select_db($database_host1nger, $host1nger);
$Result1 = mysql_query($insertSQL, $host1nger) or die(mysql_error());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="CSS/maxsuel-11-02.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="fb-root"></div>
<section id="cabecalho">
</section>
<div class="container">
<div class="sidebar1">
</div>
<div class="content">
<div id="corpp">
<div class="fatia3">
<img src="img/entrecontato.fw.png" width="242" height="35" />
<form name="form" action="<?php echo $editFormAction; ?>" method="POST">
<div> Preencha o formulário abaixo com suas dúvidas ou sugestões. </div>
<div>Seu nome :</div>
<div><input name="nome" type="text" size="40" /></div>
<div>Seu E-mail :</div>
<div><input name="email" type="text" id="email" size="40" /></div>
<div>Seu telefone :</div>
<div><input name="telefone" type="text" size="40" /></div>
<div>Comentários :</div>
<div>
<textarea name="comments" cols="55" rows="10"></textarea>
</div>
<div style="float:right;">
<input type="submit" name="enviar" id="enviar" value="Enviar" />
</div>
<input type="hidden" name="MM_insert" value="form" />
</form>
</div>
<div></div>
</div>
<!-- end .container -->
</div>
<section id="rodapé"></section>
</body>
</html>
Brother uma dica pricipalmente para você que deve estar começando com php usar os códigos prontos do Dreamweaver só ira atrapalhar você a aprender.
Agora com relação a sua duvida.
$Result1 = mysql_query($insertSQL, $host1nger) or die(mysql_error());
Essa linha é a responsavel por gravar os dados é só fazer uma verifição se a variavel $Result1 for igua a true você exibi o alerta e depois redireciona a pagina.
Pensando aqui, usando a lógica para retornar um erro seria basicamente
$Result1 = mysql_query($insertSQL, $host1nger) or die(mysql_error(echoErro Aqui"));
Então para retornar algo positivo seria :
$Result1=true("echo Mensagem aqui")
no meio do HTML ou seria errôneo ?
Sua lógica esta errada, e cara você precisa estudar php e os códigos prontos do dreamweaver só vai te atrapalhar a aprender.
No caso você usuario um if para verificar se retornou true.
Ex:
if($Result1 == true){
//executa uma ação caso os dados forem inseridos com sucesso.
}
E outra coisa você não esta validando os campos pricipalmente os campos e-mail e telefone que tem um formato correto.
da uma lida no manual de como funciona o mysql_query() e sobre if.
http://www.php.net/manual/pt_BR/function.mysql-query.php
http://www.php.net/manual/pt_BR/control-structures.if.php
Dica de materias para estudo de como gravar registros no banco de dados:
http://blog.thiagobelem.net/manipulando-dados-do-mysql-com-o-php/
http://phpsqlbr.blogspot.com.br/2009/05/inserindo-registros-pelo-php.html
http://escolacompleta.com/desenvolvimento/php/curso-php-com-mysql-aula-04-inserindo-dados-na-tabela
da um
apos gravar os dados no banco...