Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá, estou me matando com uma dúvida, gostaria de saber como posso inserir um determinado valor com o comando 'insert', porém em qualquer campo de minha escolha, como no caso, em um campo vazio.
Estou tentando montar um sistema bem simples, que seria assim:
Sistema de cadastro de usuário, onde ele só pode se cadastrar com um tipo de Chave, ele inseri a chave, e assim
pode preencher o formulário para se registrar com suas informações. Até ai tudo bem para mim, mas o problema aparece quando eu tenho que adicionar essas informações nos campos daquela determinada chave como nome, telefone, e-mail e login. Então, preciso do comando exato para o 'insert' selecionar os campos da chave que a pessoa têm, que no momento estão todos vazios.
Estou usando os seguintes comandos:
<?php
if (!isset($_SESSION)) {
session_start();
}
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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")) {
$nivel=$_POST['nivel'];
$insertSQL = sprintf("SELECT * FROM sistema_de_login WHERE nivel='$nivel'",
"INSERT INTO sistema_de_login (nome, email, telefone, login) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['nome'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['telefone'], "text"),
GetSQLValueString($_POST['login'], "text"),
GetSQLValueString($_POST['nivel'], "text"));
mysql_select_db($database_conexao, $conexao);
$Result1 = mysql_query($insertSQL, $conexao) or die(mysql_error());
$insertGoTo = "enviado.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}Carregando comentários...