Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert does not work with PHP variables
    primarykey
    data
    text
    <p>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 <code>something</code> not while using <code>$something</code>)</p> <p>Here is the code:</p> <pre><code>mysqli_query($con,"INSERT INTO Atendido (idPaciente,idDoctor,fecha,costo,tipoAtencion) values ('".$_GET['iddoctor']."', '".$_GET['idpacient']."', '".$_GET['date']."', '".$_GET['amount']."', '".$_GET['description']."')"); </code></pre> <p>and the data comes from an other page with this form:</p> <pre><code>&lt;form action="thanks/index.php" method="get"&gt; &lt;span class="largetext"&gt;ID. doctor&lt;/span&gt;&lt;br/&gt; &lt;input type="password" name="iddoctor"&gt;&lt;br/&gt; &lt;span class="largetext"&gt;ID. patient&lt;/span&gt;&lt;br/&gt; &lt;input type="password" name="idpatient"&gt;&lt;br/&gt; &lt;span class="largetext"&gt;Date&lt;/span&gt;&lt;br/&gt; &lt;input type="date" name="date"&gt;&lt;br/&gt; &lt;span class="largetext"&gt;Amount&lt;/span&gt;&lt;br/&gt; &lt;input type="number" name="amount"&gt;&lt;br/&gt; &lt;span class="largetext"&gt;Description&lt;/span&gt;&lt;br/&gt; &lt;input type="text" name="description"&gt;&lt;br/&gt;&lt;br/&gt; &lt;input type="submit" value="Accept" style="background-color:#FF5F00; color:#FFFFFF; opacity: 0.77;"&gt; &lt;/form&gt; </code></pre> <p><strong>Thank you!</strong> To everyone who noted the <a href="https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php">SQL injection</a> problem, I will also have a look onto that.</p> <p>I now works, here is the corrected code:</p> <pre><code>mysqli_query($con,"INSERT INTO Atendido (idPaciente,idDoctor,fecha,costo,tipoAtencion) VALUES ('".$_GET['idpatient']."', '".$_GET['iddoctor']."','".$_GET['date']."', '".$_GET['amount']."', '".$_GET['description']."')"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload