I want to insert into a MySQL database from a webpage using PHP, but when trying to use variables it does not work (it works just fine if I use something
not while using $something
)
Here is the code:
mysqli_query($con,"INSERT INTO Atendido (idPaciente,idDoctor,fecha,costo,tipoAtencion) values ('".$_GET['iddoctor']."', '".$_GET['idpacient']."', '".$_GET['date']."', '".$_GET['amount']."', '".$_GET['description']."')");
and the data comes from an other page with this form:
<form action="thanks/index.php" method="get">
<span class="largetext">ID. doctor</span><br/>
<input type="password" name="iddoctor"><br/>
<span class="largetext">ID. patient</span><br/>
<input type="password" name="idpatient"><br/>
<span class="largetext">Date</span><br/>
<input type="date" name="date"><br/>
<span class="largetext">Amount</span><br/>
<input type="number" name="amount"><br/>
<span class="largetext">Description</span><br/>
<input type="text" name="description"><br/><br/>
<input type="submit" value="Accept" style="background-color:#FF5F00; color:#FFFFFF; opacity: 0.77;">
</form>
Thank you! To everyone who noted the SQL injection problem, I will also have a look onto that.
I now works, here is the corrected code:
mysqli_query($con,"INSERT INTO Atendido (idPaciente,idDoctor,fecha,costo,tipoAtencion) VALUES ('".$_GET['idpatient']."', '".$_GET['iddoctor']."','".$_GET['date']."', '".$_GET['amount']."', '".$_GET['description']."')");