Advertisement
Guest User

SQL

a guest
Dec 8th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.62 KB | None | 0 0
  1. <?php
  2. include "../../Connections/conecta_site.php";
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   //Inicia aqui
  11.   $theValue = mysqli_real_escape_string($conecta, $theValue);
  12.   //Termina aqui
  13.  
  14.   switch ($theType) {
  15.     case "text":
  16.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  17.       break;    
  18.     case "long":
  19.     case "int":
  20.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  21.       break;
  22.     case "double":
  23.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  24.       break;
  25.     case "date":
  26.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  27.       break;
  28.     case "defined":
  29.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  30.       break;
  31.   }
  32.   return $theValue;
  33. }
  34. }
  35.  
  36. $editFormAction = $_SERVER['PHP_SELF'];
  37. if (isset($_SERVER['QUERY_STRING'])) {
  38.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  39. }
  40.  
  41. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
  42.   $insertSQL = sprintf("INSERT INTO newsletter (nome, email) VALUES (%s, %s)",
  43.                        GetSQLValueString($_POST['nome'], "text"),
  44.                        GetSQLValueString($_POST['email'], "text"));
  45.  
  46.   //Inicia aqui
  47.   $db_select = mysqli_select_db($STRING_DE_CONEXAO_COM_O_BANCO, "NOME_DO_SEU_BANCO");
  48.   //Termina aqui
  49.  
  50.   //Inicia aqui
  51.   $Result1 = mysqli_query($insertSQL, $db_select) or die(mysqli_error());
  52.   //Termina aqui
  53.  
  54.   $insertGoTo = "newsletter.php";
  55.   if (isset($_SERVER['QUERY_STRING'])) {
  56.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  57.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  58.   }
  59.   header(sprintf("Location: %s", $insertGoTo));
  60. }
  61. ?>
  62.  
  63. <link href="css/estilos.css" rel="stylesheet" type="text/css" />
  64.  
  65. <form method="POST" name="form" action="<?php echo $editFormAction; ?>"POST" >
  66. <ul>
  67. <li> <label class="name_newsletter" for="name">Nome:</label> <input type="nome" class="news_footer_name" name="nome"  id="nome"  maxlength="100" /></li>
  68.  
  69. <li> <label class="email_newsletter" for="email">E-mali:</label> <input type="email" class="news_footer_mail" name="email" id="email" maxlength="100"/></li>
  70.  
  71. <input class="btn_newsletter" type="submit" value="Cadastrar" id="btnSend">
  72. <input type="hidden" name="MM_insert" value="newsletter" />
  73. <input type="hidden" name="MM_update" value="newsletter" />
  74. <input type="hidden" name="MM_insert" value="form" />
  75. </form>
  76. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement