In the external PHP file I have the following code:
<!DOCTYPE html>
<?php
$servername = "localhost";
$username = "isabelso_isabel";
$password = "password";
$dbname = "isabelso_db";
$dbconn = mysql_connect($servername, $username, $password, $dbname);
mysql_select_db($dbname);
if (isset($_POST['botao_registo']))
{
$name = $_POST['nome'];
$nif = $_POST['nif'];
$sql = ("INSERT INTO Paciente (nome, id_paciente ) VALUES ('".$nome."', ' ".$nif."')");
if(mysql_query($query))
{
echo "<script>alert('INSERTED SUCCESSFULLY');</script>";
}
else
{
echo "<script>alert('FAILED TO INSERT ".mysql_error()."');</script>";
}
}
The name of the table is Paciente
and the attributes are: nome, id_paciente
The textbox names are nome, nif
.
I already have the other one:
<body>
<?php
include("user_insert.php");
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<p style="font-size: 15px"> <font face= "Verdana">
  Nome:<INPUT type="text" name="nome" size=50>
      Data de Nascimento: <input type="date" name="bday" > <br><br>
  NIF:<INPUT type="number" name="nif" size=10>            
  Telemóvel:<INPUT type="number" name="telemovel" size=10> <br><br>
  Email:<INPUT type="email" name="email" size=40><br><br>
  Password:<INPUT type="password" name="senha" size=30><br><br>
  Password:<INPUT type="password" name="senha" size=30><br><br>
  Alergias/Doenças Conhecidas:<INPUT type="text" name="doenças" size=50> <br><br>
  Observações:<br>  <textarea name="observacoes" rows="5" cols="90" maxlength="500"></textarea>
</p></font>
<br>
<br>
<br>
<br>
<br>
<div id="botao">
<input type="submit" name="botao_registo" value="ENVIAR DADOS" class=botaoEnviar />
There will be something wrong with the PHP code because when I fill in the text box and press the button to send to the database it gives the error: "FAILED TO INSERT", query was empty.