Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your <code>INSERT</code> syntax makes little sense as it is:</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>I would suggest you do the following—and use <a href="http://php.net/manual/en/function.sprintf.php" rel="nofollow"><code>sprintf</code></a>—to make formatting easier:</p> <pre><code>$insert_query = sprintf("INSERT INTO Atendido (idPaciente,idDoctor,fecha,costo,tipoAtencion) values ('%s','%s','%s','%s','%s')", $_GET['iddoctor'], $_GET['idpacient'], $_GET['date'], $_GET['amount'], $_GET['description']); mysqli_query($con,$insert_query); </code></pre> <p>What is nice about <code>sprintf</code> is it allows you to easily separate formatting logic from the data itself. Think of it as a small-scale templating system.</p> <p>Also, I would even suggest taking it one step further by doing this:</p> <pre><code>$data_keys = array('idPaciente','idDoctor','fecha','costo','tipoAtencion'); $data_values = array(); foreach($data_keys as $key) { $value = array_key_exists($key, $_GET) &amp;&amp; !empty($_GET[$key]) ? $_GET[$key] : null; if (!empty($value)) { $data_values[$key] = $value; } } if (!empty($data_values)) { $insert_query = sprintf("INSERT INTO Atendido (%s) values ('%s')", implode(',', array_keys($data_values)), implode("','", $data_values) ); echo $insert_query; mysqli_query($con,$insert_query); } </code></pre> <p>That way you have a process to filter the <code>$_GET</code> values and make the creation of the <code>INSERT</code> easier to understand irregardless of how many values you have.</p>
 

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