Jump to content

converting to PDO not working


Digitizer
 Share

Recommended Posts

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 by Digitizer
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.