Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn a mysql result to php using ajax
    primarykey
    data
    text
    <p>I've been dealing with that problem for a while, but I can't see the solution here. I am making a simple list application, and anytime the user creates a new item it should be saved to the database. The issue is that every item has a unique ID (auto-incremented), and that ID has to be on the html code when the item is appended to the list (other functions need to use it, so when it's uploaded to the database, then the ID should be selected and sended again to the original html file, but I'm not sure how to do that (in fact, I've got no idea).</p> <p>Here's my php/html code:</p> <pre><code>while($row = mysql_fetch_array($selectitems) ){ echo'&lt;html&gt; &lt;li class="i­tem" data-id="'; echo $row['IDitem']; echo '"&gt; &lt;div class="draggertab"&gt;&lt;img src="imatges/botofletxa.jpg" width="30" height="30"&gt;&lt;/div&gt; &lt;div class="deletetab"&gt;&lt;img src="imatges/botocreu.jpg" width="30" height="30"&gt;&lt;/div&gt; &lt;span class="item"&gt;'; echo $row['Text']; echo'&lt;/span&gt; &lt;/li&gt; &lt;/html&gt;'; } </code></pre> <p>The javascript:</p> <pre><code> ajax.onreadystatechange=function() { //la función responseText tiene todos los datos pedidos al servidor if (ajax.readyState==4) { //mostrar resultados en esta capa AppendItem(); //llamar a funcion para limpiar los inputs LimpiarCampos(); } } ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); //enviando los valores a registro.php para que inserte los datos ajax.send("nombre="+nom+"&amp;IDllista="+llista); } </code></pre> <p>And the PHP:</p> <pre><code>$con = mysql_connect($bd_host, $bd_usuario, $bd_password); mysql_select_db($bd_base, $con); //variables POST $nom=$_POST['nombre']; $IDllista = $_POST['IDllista']; //registra los datos del empleados $sql="INSERT INTO items (Text, IDllista) VALUES ('$nom', '$IDllista')"; mysql_query($sql,$con) or die('Error. '.mysql_error()); </code></pre> <p>There is also much more code, but I posted what I think is the most important part. It works perfectly now, I just need to send the ID.</p> <p>Thank you very much!!</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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