Deleting from a mySQL database
Posted: Sun Nov 10, 2002 3:49 pm
Hi,
I think I'm confusing myself. What I want to do is to show the user all the records in a mySQL table and give them the option to delete the record by clicking on a field.
So far, I've got
That pulls all the records from the database. But I'm not sure what the best way to go about querying the database to delete the entry would be.
My idea was a javascript that nests a PHP statement, if you see what I mean, to delete the entry from the database (criteria being the filename), or is there a more efficient way to delete the record? I'm confusing myself with it... The filename is passed to the script, i.e.
I don't know whether this is the best way, I'm just experimenting.
Any suggestions greatly appreciated,
Thanks
Jonathan
I think I'm confusing myself. What I want to do is to show the user all the records in a mySQL table and give them the option to delete the record by clicking on a field.
So far, I've got
Code: Select all
<?php
$dbconn = mysql_connect("localhost", "test", "test");
$result = mysql_select_db("jonat8", $dbconn);
if ( $result == false )
{
echo mysql_error();
} else {
$sql = "SELECT * from dalmedia";
$result = mysql_query( $sql );
if ( $result != false )
{
while ( $data = mysql_fetch_assoc( $result ) )
{
echo 'Track Details: '.
$dataї'artist'].' (<a href="javascript:deleteMedia('.
$dataї'filename'].')"><b>'.
$dataї'trackname'].'</a></b>)<br>';
}
} else {
echo mysql_error();
}
}
?>My idea was a javascript that nests a PHP statement, if you see what I mean, to delete the entry from the database (criteria being the filename), or is there a more efficient way to delete the record? I'm confusing myself with it... The filename is passed to the script, i.e.
Code: Select all
<SCRIPT LANGUAGE=JavaScript>
function deleteMedia(filename)Any suggestions greatly appreciated,
Thanks
Jonathan