vinbrutus Posted July 3, 2012 Share Posted July 3, 2012 I'm quiet new with Ajax and php. I've created a table and now a want to be able to delete an entire row with a delete button. But offcourse nothing happens when i click on the button Here i create the table, its not the entire code <script src="ajax_framework.js" language="javascript"></script> //MYSQL Statement $select = "SELECT * FROM `vliegers`"; //Plaats query in pointer $query = mysql_query($select); //While-lus met query die alles in html-tabel zet echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" id=\"table\" class=\"tinytable\">"; echo"<thead> <tr> <th class=\"nosort\"><h3>ID</h3></th> <th><h3>Naam</h3></th> <th><h3>Type</h3></th> <th><h3>Fabrikant</h3></th> <th><h3>Schaal</h3></th> <th><h3>Kitnr</h3></th> <th><h3>Magazine</h3></th> <th><h3> Verwijder</h3><th> </tr> </thead>"; echo "<tbody>"; while ($qry = mysql_fetch_array($query)) { echo "<tr><td>"; echo $qry['id']; echo "</td><td>"; echo $qry['naam']; echo "</td><td>"; echo $qry['type']; echo "</td><td>"; echo $qry['fabrikant']; echo "</td><td>"; echo $qry['schaal']; echo "</td><td>"; echo $qry['kitnr']; echo "</td><td>"; echo $qry['magazine']; echo "</td><td>";?> <button type='submit' onclick="javascript:delete(<?=$qry['id']?>);" title='Verwijderen' style='width: 38px;'> <img src='delete.png' align='absmiddle'></button> <?php echo "</td></tr>"; } echo "</tbody>"; echo "</table>"; this is the ajax_framework.js file var http3 = createObject(); function delete($id) { // Optional: Show a waiting message in the layer with ID login_response document.getElementById('insert_response').innerHTML = "Just a second..." // Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding. var id = encodeURI(document.getElementById('id').value); // Set te random number to add to URL request nocache3 = Math.random(); // Pass the login variables like URL variable http3.open('get', 'deleteEntry.php?id=' +id+ '&nocache = '+nocache3); http3.onreadystatechange = deleteReply; http3.send(null); } function deleteReply() { if(http3.readyState == 4){ var response2 = http3.responseText; // else if login is ok show a message: "Site added+ site URL". document.getElementById('insert_response').innerHTML = 'Site added:'+response2; window.location.reload(); } } And in the deleteEntry file i have the following code: <!-- Include Database connections info. --> <?php include('config.php'); //<!-- Verify if user exists for login --> if(isset($_GET['id'])){ $sql="DELETE * FROM vliegers WHERE id= ".mysql_real_escape_string($_GET['id']); $insertSite= mysql_query($sql) or die(mysql_error()); //<!-- If is set URL variables and insert is ok, show the site name --> } else { echo 'Error! Please fill all fileds!'; } ?> Can somebody give me a tip in the wright direction? thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/265142-newbie-ajax-question/ Share on other sites More sharing options...
Mahngiel Posted July 5, 2012 Share Posted July 5, 2012 Your delete query is incorrect. Take a look into how to delete items from the database/ Quote Link to comment https://forums.phpfreaks.com/topic/265142-newbie-ajax-question/#findComment-1359327 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.