Jump to content


Photo

Problema Com Registro De Dados Mysql + Php


  • Faça o login para participar
2 replies to this topic

#1 AngelMoon

AngelMoon

    Novato no fórum

  • Usuários
  • 4 posts
  • Sexo:Masculino
  • Localidade:Rio de janeiro

Posted 08/02/2012, 19:13

esse eh o arquivo index.html , abro ele escrevo nome email dedicatoria clico enviar e nao chega nada la no meu banco de dados estou usando o wamp

<!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>Untitled Document</title>
</head>



<body>
     <form action="grava.php" method="post" enctype="multipart/form-data" name="forml" id="forml">
    <table width="577" border="0" align="center" cellpadding="0" cellspacing="0">
  
      <tr>
        <td>Nome:</td>
      </tr>
      <tr>
        <td><form id="nome" name="nome" method="post" action="">
          <span id="nome">
          <label for="text1"></label>
          <input type="text" name="nome" id="nome" />
          <span class="textfieldRequiredMsg">A value is required.</span></span>
        </form></td>
      </tr>
      <tr>
        <td>Email:</td>
</tr>
      <tr>
        <td><form id="email" name="email" method="post" action="">
          <span id="email">
          <label for="text1"></label>
          <input type="text" name="email" id="email" />
          <span class="textfieldRequiredMsg">A value is required.</span></span>
        </form></td>
      </tr>
      <tr>
        <td>Dedicatoria:</td>
      </tr>
      <tr>
        <td><form id="dedicatoria" name="" method="post" action="">
          <span id="dedicatoriaa">
            <label for="dedicatoria"></label>
            <span id="dedicatoria">
            <label for="textarea1"></label>
            <textarea name="dedicatoria" id="dedicatoria" cols="45" rows="5"></textarea>
          <span class="textareaRequiredMsg">A value is required.</span></span>          </span>
        </form></td>
      </tr>
<tr>
        <td><form id="form4" name="form4" method="post" action="">
     
          <input type="submit" name="buttom" id="buttom" value="Enviar" />
        </form></td>
      </tr>
    </table>
  </div>
<script type="text/javascript">
var nome = new Spry.Widget.ValidationTextField("nome");
var email = new Spry.Widget.ValidationTextField("email");
var dedicatoria = new Spry.Widget.ValidationTextarea("dedicatoria");
</script>
</body>
</html>



arquivo contecta

<?php
	$host      =   "localhost";
	$login     =   "root";
	$password  =    "";
	$database  =   "clientes";
	$tabela    =   "registrar";
	$link      =    mysql_connect($host,$login,$password) or die ("erro ao tentar conectar");
	
?>



esse eh o arquivo grava

<?php include('conecta.php');?>
<?php
$nome = $_POST['nome'];
$email = $_POST['email'];
$dedicatoria = $_POST['dedicatoria'];

$query = "INSERT INTO $tabela VALUES ('NULL','$nome','$email',
'$dedicatoria')";

if(mysql_db_query($database, $query, $link)) {
print("<p class=titulo_big> A insersao foi executada com sucesso!</p>");
} else {
print("<p class=titulo_big>A consulta nao foi executada!</p>");
}
mysql_close($link);

?>



#2 Andreia Regina

Andreia Regina

    Veterano

  • Conselheiros
  • 1347 posts
  • Sexo:Feminino
  • Localidade:PR
  • Interesses:PHP; MySQL; Javascript; CSS; tudo ligado ao desenvolvimento web.

Posted 09/02/2012, 13:47

Defina os campos que você quer gravar, exemplo:
 $query="INSERT INTO tabela (campo1,campo2,campo3) VALUES ('$valor_campo1','$valor_campo2','$valor_campo3')";
 $verifica=mysql_query($query) or die(mysql_error()) ;

Procure por INSERT mysql no google para você ver a sintaxe correta.

Bons estudos!

Fórum WMO - Conselheira - Na equipe desde 31/01/2006.
Links importantes: Regras de conduta - Busca do fórum


#3 AngelMoon

AngelMoon

    Novato no fórum

  • Usuários
  • 4 posts
  • Sexo:Masculino
  • Localidade:Rio de janeiro

Posted 09/02/2012, 17:29

It is possible to write the INSERT INTO statement in two forms.

The first form doesn't specify the column names where the data will be inserted, only their values:

INSERT INTO table_name
VALUES (value1, value2, value3,...)
The second form specifies both the column names and the values to be inserted:

INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

existem 2 formas, a que eu fiz foi a segunda nao? po se nao esta errado o q esta?

nas actions de cada campo do bottom eu coloquei grava.php e pelo menos funfou mas aparece esse erro oh


Notice: Undefined index: nome in C:\wamp\www\cadastro estrela\grava.php on line 3

Notice: Undefined index: email in C:\wamp\www\cadastro estrela\grava.php on line 4

Notice: Undefined index: dedicatoria in C:\wamp\www\cadastro estrela\grava.php on line 5

Warning: mysql_query() expects at most 2 parameters, 3 given in C:\wamp\www\cadastro estrela\grava.php on line 10

A consulta nao foi executada!


RESOLVI e nao tinha nada a ver com o $tabela ( bla bla blah) nao. Mexi ali acola e ai funfou, nem sei exatamente o q eu fiz eoaieoiaeoaioea




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq