Says it saves to mysql but not saved to the database

Asked

Viewed 461 times

0

Form:

<!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=iso-8859-1" />
<title>Cadastrar Associado</title>
<style type="text/css">

</head>

<body>
<table width="625" border="0" align="center">
   <tr>
        <td width="69">
        <fieldset>
        <legend><font size="3" face="verdana"><strong>Cadastro de Associado</strong></font> </legend>
                  <span class="style1"><font size="1" face="verdana"><b>Todos os campos são obrigatórios!</b></font></span><br><br>
<form id="cadastro" name="cadastro" method="post" action="grava_matricula_mensalidade.php">
  <font size="2" face="verdana"><b>
  <table width="625" border="0">
    <tr>
      <td width="69">Matrícula:</td>
      <td width="546"><input name="matricula" type="text" id="matricula" size="4" maxlength="4" /></span></td>
    </tr>
    <tr>
      <td colspan="2"><p>
      <br>
        <input name="cadastrar" type="submit" id="cadastrar" value="Cadastrar" /> 
        <br><br>
        </td>
    </tr>
  </table>
  </font></b>
</form>
    </fieldset>
        </td>
    </tr>
</table>

</body>
</html>

grava_matricula_mensalidade.php:

<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php 

$matricula = $_POST['matricula'];


$conexao1 = mysql_connect("localhost","root","123");
if (!$conexao1)
    die ("Erro de conexão com localhost, o seguinte erro ocorreu -> ".mysql_error());

$banco = mysql_select_db("coloniaam34",$conexao1);
if (!$banco)
    die ("Erro de conexão com banco de dados, o seguinte erro ocorreu -> ".mysql_error());



$query = ("INSERT INTO mensal_anual (matricula) VALUE ('$matricula')");

mysql_query($query,$conexao1);

echo "Seu cadastro foi realizado com sucesso!<br>Agradecemos a atenção.";
?>
<p>

<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=cadastrar_matricula.html">
</body>
</html>

NOTE: Says you registered correctly, but not saved in mysql BD.

Would anyone know to report a mistake?

  • With error or success the message will always be displayed, need a conditional. Your code should look something like if(mysql_query($query,$conexao1)) echo 'sucesso'; else die(mysql_error());

  • But what is the mistake of not saving? (pq the worry would not be error msg, but the reason for not saving).

  • Any problems with Insert. Changed code? show no error?

  • I have another identity and saved, I copied changed only the table. After the copy, it does not save more. (change the code not, but I understood your placement)

1 answer

4

Syntax error

$query = ("INSERT INTO mensal_anual (matricula) VALUES ('$matricula')");

IS VALUES and not VALUE

Browser other questions tagged

You are not signed in. Login or sign up in order to post.