Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa tarde pessoal estou com dificuldade em redirecionar o usuario após ele inserir um registro em um formulario:
Codigo que estou usando
1º o php:
<?php require_once('Connections/loco.php'); ?>
<?php
// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="add_erro.php";
$loginUsername = $_POST['add_ip'];
$LoginRS__query = sprintf("SELECT add_ip FROM servidor WHERE add_ip=%s", GetSQLValueString($loginUsername, "text"));
mysql_select_db($database_loco, $loco);
$LoginRS=mysql_query($LoginRS__query, $loco) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header('Localização: add_erro.php');
exit;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "" . htmlentities($_SERVER['QUERY_STRING']);
header('Localização:add_sucesso.php');
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO servidor (id, add_nome, add_versao, add_ip, add_banner, add_porta) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['add_nome'], "text"),
GetSQLValueString($_POST['add_versao'], "text"),
GetSQLValueString($_POST['add_ip'], "text"),
GetSQLValueString($_POST['add_banner'], "text"),
GetSQLValueString($_POST['add_porta'], "int"));
mysql_select_db($database_loco, $loco);
$Result1 = mysql_query($insertSQL, $loco) or die(mysql_error());
$insertGoTo = "add_sucesso.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '')) ? "" : "";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
}
?>
2° O formulario:
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Nome do Servidor: </td>
<td><input name="add_nome" type="text" required size="32" maxlength="15"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Versao do Servidor: </td>
<td><input name="add_versao" type="text" required id="add_versao" autocomplete="off" size="32" maxlength="10"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">IP do Servidor: </td>
<td><input name="add_ip" type="text" required value="" size="32" maxlength="30"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Banner do Servidor: </td>
<td><input name="add_banner" type="text" id="add_banner" value="http://minecraftservidores.net/img/sem_banner.png" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap>Porta do Servidor: </td>
<td><input name="add_porta" type="text" required id="add_porta" value="25565" size="32" maxlength="7"></td>
</tr>
</table>
<table align="center">
<tr valign="baseline">
<td><input type="submit" value="Enviar">
<input type="reset" name="reset" id="reset" value="Limpar campos"></td>
</tr>
</table>
<p>
<input type="hidden" name="MM_insert" value="form1">
</p>
</form>
Se alguem poder me ajudar ficaria agradecido.
Carregando comentários...