Digitizer Posted September 11, 2014 Share Posted September 11, 2014 (edited) Hello guys, I have been away for a couple of days. Its nice to be back Yesterday night I was practicing an AJAX/PHP delete tutorial and file "delete.php" was wrtiten in mysql* which I converted to PDO but it didnt seem to work after conversion. The three bits of code are as follows //I got the results using PDO::FETCH_ASSOC in following div getting ID of row in link while ($r = $getData->fetch(PDO::FETCH_ASSOC)){ echo (" <div class='record' id='record-".$r['id']."'> <a href='?delete=".$r['id']."' class='delete'>[x]</a> </div> "); } $(document).ready(function() { $('a.delete').click(function(e) { e.preventDefault(); var parent = $(this).parent(); $.ajax({ type: 'get', url: 'delete.php', data: 'ajax=1&delete=' + parent.attr('id').replace('record-',''), beforeSend: function() { parent.animate({'backgroundColor':'#fb6c6c'},300); }, success: function() { parent.slideUp(300,function() { parent.remove(); }); } }); }); }); and delete.php contains include "inc.connect.php"; if(isset($_GET['delete'])){ $id = $_GET['delete']; $query = "DELETE FROM tempdata WHERE id=?"; $runThis = $db->prepare($query); $runThis->bindValue(1,$id); $runThis->execute(); } /*The problem I am facing is in delete.php. because If i run the same script in mysql_*, it works, which is as follows first (I had to write connect in mysql as original connection is written in PDO) ------------------------------------------------------ $con = mysql_connect('localhost','munni****','*******'); mysql_select_db('stockcontrol',$con); if(isset($_GET['delete'])) { $result = mysql_query('DELETE FROM tempdata WHERE id = '.(int)$_GET['delete'],$con); } mysql_close($con); */ Edited September 11, 2014 by Digitizer Quote Link to comment https://forums.phpfreaks.com/topic/290996-converting-to-pdo-not-working/ Share on other sites More sharing options...
ginerjm Posted September 11, 2014 Share Posted September 11, 2014 1 - do you have error checking turned on? 2 - the bindvalue function returns a result. Did you bother to check that it ran ok? No. 3 - the manual gives you the proper syntax for this function. Read it. Quote Link to comment https://forums.phpfreaks.com/topic/290996-converting-to-pdo-not-working/#findComment-1490737 Share on other sites More sharing options...
Digitizer Posted September 11, 2014 Author Share Posted September 11, 2014 1 - do you have error checking turned on? 2 - the bindvalue function returns a result. Did you bother to check that it ran ok? No. 3 - the manual gives you the proper syntax for this function. Read it. Thanks for reply my friend, 1. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // is set as error check 2. If I run delete.php?delete=3 //for example, in browser directly, the script runs fine and deletes the corresponding row from table 3. I have not read the manual yet though Quote Link to comment https://forums.phpfreaks.com/topic/290996-converting-to-pdo-not-working/#findComment-1490741 Share on other sites More sharing options...
mac_gyver Posted September 11, 2014 Share Posted September 11, 2014 does the 'view source' of the html have the expected values for the id='...' attributes? edit: am also fairly certain that when pdo is doing emulated prepared queries (the unfortunate default), that bind statements don't return or throw any database/data releated errors. Quote Link to comment https://forums.phpfreaks.com/topic/290996-converting-to-pdo-not-working/#findComment-1490766 Share on other sites More sharing options...
jazzman1 Posted September 11, 2014 Share Posted September 11, 2014 we actually need to see what data the client (your browser) sends to the server. Add var_dump() on top of the delete.php file: var_dump($_GET); Quote Link to comment https://forums.phpfreaks.com/topic/290996-converting-to-pdo-not-working/#findComment-1490770 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.