Current location: Hot Scripts Forums » Programming Languages » PHP » Delete function not working properly.


Delete function not working properly.

Reply
  #1 (permalink)  
Old 12-27-11, 04:56 AM
solidnailer solidnailer is offline
New Member
 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
X_X Delete function not working properly.

I wrote a simple jukebox script, which has the ability to add in and delete songs.
The script works seems fine when i upload it into my server but when i manually add in songs to the server, the script is unable to delete it despite displaying the songs. When i select the delete function it tells me that the song has been deleted but when i refresh the page it shows up again.
I dont know what went wrong, please help me. The script is included below. Thank you.

DeleteSong.php
PHP Code:

<?php

$HOST 
'localhost';
$USERNAME 's82332';
$PASSWORD '^0e900ad8';
$DB 's82332';
// open connection 
$link mysqli_connect($HOST,$USERNAME,$PASSWORD,$DB );
// build SQL statement 
$query1 "SELECT COUNT(*) FROM songs";
$query2 "SELECT * FROM songs ORDER BY Songs_id ASC ";

// execute SQL statement
$result1 mysqli_query($link$query1) or die(mysqli_error($link));
$result2 mysqli_query($link$query2) or die(mysqli_error($link));

$row1 mysqli_fetch_row($result1);

//echo "There are " . $row1[0] . " songs in total.";

mysqli_close($link);
?>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Delete Songs</title>
    </head>
    <body>
            <h1 align="center"><i> THE MUSIC JUKE BOX</i> </h1>
            <h6 align ="center"><i> YOUR VERY OWN ONLINE MUSIC LIBRARY</i></h6>
            <h4 align="center"><?echo "There are " $row1[0] . " songs in total.";?></h4>
            <form  action="dodelete.php" method="post" name="frmDelete" onsubmit="return validateForm ();">
                
        <table border = "1" align ="center">    
            <tr>                
                <th>Title</th>
                <th>Time</th>
                <th>Genre</th>
                <th>Album</th>
                <th>Artist</th>
            </tr>
        
        <?php
        
while ($row2 mysqli_fetch_assoc($result2)) {
           
// $id = $row2['Songs_id'];
            
$title $row2['Songs_title'];
            
$time $row2['Songs_time'];
            
$genre $row2['Songs_genre'];
            
$album $row2['Songs_album'];
            
$artist $row2['Songs_artist'];
            
?>

        <tr>
            
            <td><?php echo $title?></td>
            <td><?php echo $time?></td>
            <td><?php echo $genre?></td>
            <td><?php echo $album?></td>
            <td><?php echo $artist?></td>
            <td><input type="submit" value="DELETE" /></td></tr>
        <?php
    
}
    
?>
</table>
            </form>               
</body>
</html>
DoDelete.php
PHP Code:

<?php

session_start
();

$error_msg "";
//$Register_username = $_POST['Register_username'];
//$Register_password = $_POST['Register_password'];
//$id = $_POST['Songs_id'];
$title $_POST['Songs_title'];
$time $_POST['Songs_time'];
$genre $_POST['Songs_genre'];
$album $_POST['Songs_album'];
$artist $_POST['Songs_artist'];

$HOST 'localhost';
$USERNAME 's82332';
$PASSWORD '0e900ad8';
$DB 's82332';

$link mysqli_connect($HOST,$USERNAME,$PASSWORD,$DB);

$link mysqli_connect('localhost''s82332''0e900ad8''s82332') or die(mysqli_connect_error());

//$query="DELETE FROM songs WHERE Songs_title='".$Songs_title."'";
$query="DELETE FROM `s82332`.`songs` WHERE `songs`.`Songs_title` ='".$title."'";
$status mysqli_query($link$query)or die(mysqli_error($link)) ;

if (
$status) {
    
$message ='<p>Record Deleted</p><p>Click <a href="deletesong.php">BACK</a> to proceed to the playlist page!</p>';
    
   
}else{
    
$message '<p>class="OOPS!!">Error deleting!.<a href ="deletesong.php">Back</a></p>';
    
}
            
//$query = "DELETE FROM assets WHERE id=$index";
           // $result = mysqli_query($link, $query) or die('Error querying database');
            //echo "Delete project successfully<br>";
mysqli_close($link);
?>

 <?php
      
echo $message;
  
?>
MultipleDelete.php
PHP Code:

<?php

$HOST 
'localhost';
$USERNAME 's82332';
$PASSWORD '0e900ad8';
$DB 's82332';
// open connection 
$link mysqli_connect($HOST,$USERNAME,$PASSWORD,$DB );
// build SQL statement 
//$query1 = "SELECT COUNT(*) FROM songs";
$query2 "SELECT * FROM songs ORDER BY Songs_id ASC ";

// execute SQL statement
//$result1 = mysqli_query($link, $query1) or die(mysqli_error($link));
$result2 mysqli_query($link$query2) or die(mysqli_error($link));

//$row1 = mysqli_fetch_row($result2);

//echo "There are " . $row1[0] . " songs in total.";

mysqli_close($link);
?>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Delete Songs</title>
    </head>
    <body>
            <h1 align="center"><i> THE MUSIC JUKE BOX</i> </h1>
            <h6 align ="center"><i> YOUR VERY OWN ONLINE MUSIC LIBRARY</i></h6>
            <form  action="dodelete.php" method="post" name="frmDelete" onsubmit="return validateForm ();">
        <table border = "1" align ="center">    
            <tr>              
                <th>Title</th>
                <th>Time</th>
                <th>Genre</th>
                <th>Album</th>
                <th>Artist</th>
            </tr>
        
        <?php
        
while ($row2 mysqli_fetch_assoc($result2)) {
           
// $id = $row2['Songs_id'];
            
$title $row2['Songs_title'];
            
$time $row2['Songs_time'];
            
$genre $row2['Songs_genre'];
            
$album $row2['Songs_album'];
            
$artist $row2['Songs_artist'];
            
?>

        <tr>          
            <td><?php echo $title?></td>
            <td><?php echo $time?></td>
            <td><?php echo $genre?></td>
            <td><?php echo $album?></td>
            <td><?php echo $artist?></td>
            <td><input type="checkbox" name="songs" value="songs"  /></td></tr>
            
        <?php
    
}
    
?>
        <td colspan="100"><input type="submit" value="DELETE" /></td>
</table>

            </form>               
</body>
</html>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating Age Help jamesbuk PHP 9 03-07-09 01:21 PM
Re-ordering with ORDER BY not working properly mike_jandreau PHP 1 09-19-06 03:11 PM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 09:50 AM


All times are GMT -5. The time now is 08:59 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.