0

Redirecionar apos gravar cadastro

criado por janaina scheffel em 30/01/2013 7:33am
Olá pessoal tudo bem?
Sou nova no fórum e iniciante em PHP.
Estou com um problema. Estou estudando PHP sozinha pela internet. No decorrer dos estudos apareceu um problema que não consigo resolver.
Criei uma pagina para cadastro de clientes, tudo funciona a inserção de dados o banco de dados, mas apos clicar no botão cadastrar ao invés de gravar e redirecionar para a página de confirmação ele grava os dados, limpa o formulário e permanece na mesma página.

Por favor já fiz varias pesquisa na net, inclusive aqui no fórum, tentei varias alternativas, mas não da certo será que alguém pode tentar me ajudar?

Desde já agradeço a atenção de vocês.

Código:

<?php require_once('Connections/conectasistema.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"] == "form1")) {
$insertSQL = sprintf("INSERT INTO clientes (nome, email, telefone, mensagem) VALUES (%s, %s, %s, %s)", GetSQLValueString($_POST['nome'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['telefone'], "text"),
GetSQLValueString($_POST['mensagem'], "text"));

mysql_select_db($database_conectasistema, $conectasistema);
$Result1 = mysql_query($insertSQL, $conectasistema) or die(mysql_error());

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

Lista de Respostas:

0
01/07/2013 10:59am
(~12 anos atrás)
leandro respondeu:
O erro pode estar no formulário html.
na opção "action post" do formulário html você tem que indicar qual a página receberá os dados que estão sendo inseridos no formulário.
Ao fazer isso, o formulário irá enviar para sua página php.
depois que inserir os dados no banco, basta usar ao final do códio php o comando header ("location:http://sua nova pagina")

Nova Resposta:

(Você pode usar tags como <b>, <i> ou <code>. URLs serão convertidas para links automaticamente.)