Forum Moderators: open
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!