MySQLi não insere os dados no banco de dados
Olá! Boa tarde.
Estou fazendo um formulário de cadastro (bem simples) com PHP e MySQLi, porém não consigo exito para inserir os dados no meu Banco de Dados . Quando esta utilizando o MySQL estava inserido o conteúdo digitado nos campos do formulário, porém na página do formulário (atrás do formulário aparecia o alerta de que o MySQL estava obsoleto e pedia para utilizar o MySQLi ou PDO). Então fui pesquisar sobre o MySQLi sobre como "transformar o mysql em msqli". Consegui fazer a conexão com o Bando de Dados com MySQLi, porém não esta inserindo o conteúdo no Banco de Dados. Fiz vários testes de formulários de cadastro com msqli (que encontrei nas pesquisas na internet), li o manual do MySQLi tbm, mas ainda continuo com essa dificuldade.
Abaixo o código que utilizei:
Conexão:
<?php
$hostname_conecta_site = "localhost";
$database_conecta_site = "conexão";
$username_conecta_site = "Admin";
$password_conecta_site = "minha senha";
$conecta = mysqli_connect($hostname_conecta_site, $username_conecta_site, $password_conecta_site) or trigger_error(mysqli_error(),E_USER_ERROR);
?>
Formulário:
<?php require_once('../../Connections/conecta_site.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("mysqli_real_escape_string") ? mysqli_real_escape_string($theValue) : mysqli_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"] == "form")) {
$insertSQL = sprintf("INSERT INTO newsletter (nome, email) VALUES (%s, %s)",
GetSQLValueString($_POST['nome'], "text"),
GetSQLValueString($_POST['email'], "text"));
mysqli_select_db($database_conecta_site, $conecta_site);
$Result1 = mysqli_query($insertSQL, $conecta_site) or die(mysqli_error());
$insertGoTo = "newsletter.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<link href="css/estilos.css" rel="stylesheet" type="text/css" />
<form method="POST" name="form" action="<?php echo $editFormAction; ?>"POST" >
<ul>
<li> <label class="name_newsletter" for="name">Nome:</label> <input type="nome" class="news_footer_name" name="nome" id="nome" maxlength="100" /></li>
<li> <label class="email_newsletter" for="email">E-mali:</label> <input type="email" class="news_footer_mail" name="email" id="email" maxlength="100"/></li>
<input class="btn_newsletter" type="submit" value="Cadastrar" id="btnSend">
<input type="hidden" name="MM_insert" value="newsletter" />
<input type="hidden" name="MM_update" value="newsletter" />
<input type="hidden" name="MM_insert" value="form" />
</form>
</ul>
Os alertas de erro que aparecem são :
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\wamp64\www\meusite\arquivos\form.php on line 10
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\wamp64\www\meusite\arquivos\form.php on line 44
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\wamp64\www\meusite\arquivos\form.php on line 45
Mas eu não estou sabendo identificar os parâmetros que faltam e onde os acrescentar.
Obs.:Estou utilizando o Dreamweaver CS6 e o Wampserver.
Esses códigos acima formam os que ao menos consegui estabelecer a conexão.
Gostaria do auxilio de vocês para resolver esse problema.
Agradeço a atenção!Discussão (15)
Carregando comentários...