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

(Resolvido) alert de insert mysql php


Paulo TI Rede Brasil

Pergunta

bom dia...

Preciso de uma ajuda... fiz meio nas coxas um formulario php com insert em um banco mysql e gostaria de colocar um alert em js que confirme o inserte no banco... é possivel ? alguém pode me ajudar ?

segue o codigo:

<?php require_once('Connections/path.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 registros (id, carregamento, motorista, `data`, cod_venda, quantidade, mercadoria, vlr_devolucao,funcionario) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",

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

GetSQLValueString($_POST['carregamento'], "text"),

GetSQLValueString($_POST['motorista'], "text"),

GetSQLValueString($_POST['data'], "text"),

GetSQLValueString($_POST['cod_venda'], "text"),

GetSQLValueString($_POST['quantidade'], "text"),

GetSQLValueString($_POST['mercadoria'], "text"),

GetSQLValueString($_POST['vlr_devolucao'], "text"),

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

mysql_select_db($database_path, $path);

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

}

?>

<style type=text/css">

<!--

body {

background-color: #CCC;

text-transform:uppercase

}

-->

</style>

&lt;script type="text/javascript">

/* Autor: Mario Costa */

function formatar_moeda(campo, separador_milhar, separador_decimal, tecla) {

var sep = 0;

var key = '';

var i = j = 0;

var len = len2 = 0;

var strCheck = '0123456789';

var aux = aux2 = '';

var whichCode = (window.Event) ? tecla.which : tecla.keyCode;

if (whichCode == 13) return true; // Tecla Enter

if (whichCode == 8) return true; // Tecla Delete

key = String.fromCharCode(whichCode); // Pegando o valor digitado

if (strCheck.indexOf(key) == -1) return false; // Valor inválido (não inteiro)

len = campo.value.length;

for(i = 0; i < len; i++)

if ((campo.value.charAt(i) != '0') && (campo.value.charAt(i) != separador_decimal)) break;

aux = '';

for(; i < len; i++)

if (strCheck.indexOf(campo.value.charAt(i))!=-1) aux += campo.value.charAt(i);

aux += key;

len = aux.length;

if (len == 0) campo.value = '';

if (len == 1) campo.value = '0'+ separador_decimal + '0' + aux;

if (len == 2) campo.value = '0'+ separador_decimal + aux;

if (len > 2) {

aux2 = '';

for (j = 0, i = len - 3; i >= 0; i--) {

if (j == 3) {

aux2 += separador_milhar;

j = 0;

}

aux2 += aux.charAt(i);

j++;

}

campo.value = '';

len2 = aux2.length;

for (i = len2 - 1; i >= 0; i--)

campo.value += aux2.charAt(i);

campo.value += separador_decimal + aux.substr(len - 2, len);

}

return false;

}

</script>

&lt;script language="JavaScript">

if (document.all){

document.onkeydown = function (){

var key_f5 = 116; // 116 = F5

if (key_f5==event.keyCode){

event.keyCode = 27;

return false;

}

}

}

function envia()

{

document.formulario.submitButton.disabled = true;

document.formulario.submit();

}

</script>

&lt;script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>

<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />

<style type="text/css">

<!--

.style1 {font-size: 12px}

-->

</style>

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

<table width="100%" border="0">

<tr> </tr>

</table>

</form>

<table width="100%" border="0">

<tr>

<td> </td>

<td width="650" background="img/9.jpg"><form method="post" name="form1" action="<?php echo $editFormAction; ?>">

<table width="650" border="0">

<tr>

<td width="51%"><p>Carregamento:

<br />

<span id="sprytextfield1">

<input name="carregamento" type="text" id="carregamento" value="" size="30" />

<span class="textfieldRequiredMsg">Um carregamento é necessário.</span></span></p></td>

<td width="24%">Data :<br />

<span id="sprytextfield5">

<input name="data" type="text" id="data" value="<?php echo date('d/m/Y' ); ?>" size="12" />

<span class="textfieldRequiredMsg">Uma data é necessária.</span></span></td>

<td width="25%">Funcionario :

<span id="sprytextfield3">

<input name="funcionario" type="text" id="funcionario" value="<?=$_SESSION['login];?>" size="20" />

<span class="textfieldRequiredMsg">Um Funcionario é necessário.</span></span></td>

</tr>

<tr>

<td><p>Motorista: <br />

<span id="sprytextfield2">

<input name="motorista" type="text" id="motorista" value="" size="50" />

<span class="textfieldRequiredMsg">Um Motorista é necessário.</span></span></p></td>

<td width="49%" colspan="2"> </td>

</tr>

</table>

<p> </p>

<table width="650" border="0">

<tr>

<td>Cod. Venda:</td>

<td>Quant.:</td>

<td>Mercadoria:</td>

<td colspan="2">Vlr. Devolução:</td>

</tr>

<tr>

<td><span id="sprytextfield6">

<input name="cod_venda" type="text" id="cod_venda" value="" size="10" />

<span class="textfieldRequiredMsg">Um valor é necessário.</span></span></td>

<td><span id="sprytextfield7">

<input name="quantidade" type="text" id="quantidade" value="" size="10" />

<span class="textfieldRequiredMsg">Digite a quantidade.</span></span></td>

<td><span id="sprytextfield8">

<input name="mercadoria" type="text" id="mercadoria" value="" size="50" />

<span class="textfieldRequiredMsg">Digite a mercadoria.</span></span></td>

<td colspan="2"><span id="sprytextfield4">

<input name="vlr_devolucao" size="20" length="15" />

<span class="textfieldRequiredMsg">Digite um cod. venda.</span></span></td>

</tr>

<tr>

<td> </td>

<td> </td>

<td> </td>

<td> </td>

<td> </td>

</tr>

<tr>

<td> </td>

<td> </td>

<td> </td>

<td> </td>

<td> </td>

</tr>

<tr>

<td> </td>

<td> </td>

<td> </td>

<td><label>

<input type="Reset" value="Limpar " />

</label></td>

<td><input type="submit" value="Inserir registro" onClick="alert('Cadastro Efetuado com Sucesso')")>

</td>

</tr>

</table>

<p>

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

<span class="textfieldFlashText style1">Olá :

<?=$_SESSION['login'];?>

_Para voltar clique <a href="logado.php">aqui</a>.</span></p>

</form></td>

<td> </td>

</tr>

</table>

<br />

<table width="100%" border="0">

<tr>

<td> </td>

<td> </td>

<td><div align="right" class="textfieldFlashText style1"></div></td>

</tr>

</table>

&lt;script type="text/javascript">

<!--

var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");

var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");

var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");

var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4");

var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5");

var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6");

var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7");

var sprytextfield8 = new Spry.Widget.ValidationTextField("sprytextfield8");

//-->

</script>

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

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...