Ir para conteúdo
Fórum Script Brasil
  • 0

Mostrar Resultado Após inserir dados


Shirleyson

Pergunta

Olá pessoal tudo bom? espero que sim,

Eu estou tentando desenvolver um pequeno script de protetor de link, Após a pessoa inserir o link ele deve retornar o id do link cadastrado na mesma tela.

Minha dificuldade está sendo em trazer de volta o id que acaba de ser cadastrado, Tentei criar um recordset e pra ele buscar pelo link cadastrado e retornar o id mais não funcionou muito bem, Será que alguém poderia me ajudar?

Eis o que já criei

<?php require_once('Connections/mysql.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 link (link_id, link_url) VALUES (%s, %s)",

GetSQLValueString($_POST['link_id'], "int"),

GetSQLValueString($_POST['link_url'], "text"));

mysql_select_db($database_mysql, $mysql);

$Result1 = mysql_query($insertSQL, $mysql) or die(mysql_error());

$insertGoTo = "index.php?protegido=true";

if (isset($_SERVER['QUERY_STRING'])) {

$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

$insertGoTo .= $_SERVER['QUERY_STRING'];

}

header(sprintf("Location: %s", $insertGoTo));

}

$colname_resultado = "-1";

if (isset($_POST['FORM.link_url'])) {

$colname_resultado = $_POST['FORM.link_url'];

}

mysql_select_db($database_mysql, $mysql);

$query_resultado = sprintf("SELECT * FROM link WHERE link_url = %s", GetSQLValueString($colname_resultado, "text"));

$resultado = mysql_query($query_resultado, $mysql) or die(mysql_error());

$row_resultado = mysql_fetch_assoc($resultado);

$totalRows_resultado = mysql_num_rows($resultado);

?><!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>Super Protetor</title>

</head>

<body>

<table width="900" border="0" align="center" bgcolor="#FFFFFF">

<tr>

<td><h1 align="center">Super Protetor</h1></td>

</tr>

<tr>

<td><div align="center">

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">

<table align="center">

<tr valign="baseline">

<td width="154" align="right" nowrap="nowrap">Link que deseja proteger:</td>

<td width="314"><input type="text" name="link_url" value="" size="40" /></td>

</tr>

<tr valign="baseline">

<td nowrap="nowrap" align="right"> </td>

<td>

<div align="center">

<input type="submit" value="Proteger Link" />

</div></td>

</tr>

</table>

<input type="hidden" name="link_id" value="" />

<input type="hidden" name="MM_insert" value="form1" />

</form>

</div></td>

</tr>

<tr>

<?php if(isset($_GET["protegido])) { ?> <td>id do seu link é: <?php echo $row_resultado['link_id']; ?></td><?php } ?>

</tr>

</table>

</body>

</html>

<?php

mysql_free_result($resultado);

?>

TENTEI POR DENTRO DO CODEBOX DO FORUM MAIS TAVA DANDO ERRO... DIZENDO QUE não EXISTIA UAHSUHAS

oBRIGADO A TODOS QUE TENTAREM AJUDAR.

Link para o comentário
Compartilhar em outros sites

4 respostass a esta questão

Posts Recomendados

  • 0

1º esqueça o DW para fazer a consulta e conecxao, faça na "unha" é bem melhor e aprende mais. (opniao minha).

Quando fizer o cadastro faça uma verificaçao se foi cadastrado se tudo ok retorne os dados como se faz para ter uma consulta normal.

tipo

if(ok){
 retorna dados..
}

Tinha esquecido, para fazer o retorno você vai ter que pedir pleo ultimo id cadastrado na ordem DESC

Editado por João F. Melo
Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...