Forum Moderators: open

Message Too Old, No Replies

Problem deleting from a database

         

ajcether

1:06 pm on Jun 19, 2008 (gmt 0)

10+ Year Member



Hello, I've been having a hard time with this for a while now.

The page is a list of links to profiles for people in a company.
I am having trouble getting the page to delete a profile from the database. I want to be able to click a link the says "Delete" underneath a profile's listing on the page and have that profile be removed from the database.

Currently, this is the code I have:

profile.js:


function deleteProfile(id) {
new Ajax.Updater('profileList['+id+']', url+'profile_release_handler.php', {method: 'post', parameters: {delete: id} });
}

profiles.php:


<?
dbConnect(db);
$res = dbQuery(dbInfo);
require_once('profile_handler.php');
?>
<script "text/javascript">
<ul id="profiles">
<? while ( $p = mysql_fetch_assoc($res) ): ?>
<? $pid = $p['id']; ?>
<li id="profileList[<?=$p['id']?>]">
<a href="#" onclick="deleteProfile(<?=$p['id']?>);">Delete</a>
</li>
<? endwhile; ?>
</ul>
</script>

profile_handler.php:


if (isset($_POST['delete'])) {
mysql_query(sprintf("DELETE FROM db WHERE id = '%d'", $_POST['delete']), $conn) or die(mysql_error());
echo "Profile {$_POST['delete']} has been deleted.";
}

I've narrowed the problem down to "parameters: {delete: id}" in the javascript (if I comment this out, everything happens except the actual deletion). The error I get in the Safari Web Inspector is "Can't find variable: deleteProfile". Also, this code works perfectly in Firefox...which is weird, so maybe theres an incompatibility or a syntax error that FF is fixing?

Any suggestions you could offer would be great,
Thanks!

ajcether

1:59 pm on Jun 20, 2008 (gmt 0)

10+ Year Member



Nevermind, turned out to be an easy fix...needed 'delete': id instead of delete: id