Thread: Delete fucntion

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    Delete fucntion


    Hello Guys. I have got a delete script, but for some reasons it doesn't work. i need your help to see what i do wrong.
    Here is the code:
    <?php
    if(isset($_GET['album_id'])) {
    $album_id = $_GET['album_id'] ;
    delete_album($album_id);
    header("Location: albums.php");
    exit();
    }

    function delete_album($album_id){
    $album_id = (int)$album_id;

    $query_delete = mysql_query("DELETE FROM `albums` WHERE `album_id` ='".$album_id."' AND `user_id` = '".$_SESSION['user_id']."'");

    }

    Help me out please on this one)))
  2. #2
  3. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,184
    Rep Power
    492
    Hi there

    I'll forgo the usual "please wrap your code in PHP tags" as it's clear that nobody actually bothers to listen to me; I'll also forgo suggesting you read the New User Guide which has some excellent debugging ideas in there.

    I guess that doesn't leave a lot to say really.
    Goodbye and good luck

    ps. Have you actually tried any debugging, such as echo'ing values to the screen to see what query you're actually running or that the required variables are set, or - god forbid - tried the SQL in something like PhpMyAdmin ? If not, regardless of my lack of willing to help, I will suggest that you do that; if you hagve done that already, a) why didn't you say so and b) what was the result?
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  4. #3
  5. No Profile Picture
    Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    57
    Rep Power
    0
    Hi,

    There is no "session_start()". If that's not the reason, I second badger_fruit.

    We all would love to be able to read peoples' minds and and test the code directly on their computer. But unfortunately, we can't. So saying that something "doesn't work" and giving us a code snippet isn't enough. That's like I said "my car doesn't work" and give you a photo of the engine. Would you be able to help me?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0
    Hello guys. sorry, been away. i hope you will see where is my mistake in here. i am new to php and can't figure out what i do wrong in here. thanks for reading.

    here is the whole code:
    <?php
    ob_start();
    session_start();

    mysql_connect('localhost','root','');
    mysql_select_db('visual');

    include 'func/album.func.php';
    include 'func/image.func.php';
    include 'func/user.func.php';
    include 'func/thumb.func.php';

    ?>

    <?php

    $user_id = $_SESSION['user_id'];
    function get_albums($user_id)
    {
    $albums = array();
    // not always have got to put brackets

    $albums_query = "SELECT `albums`.`album_id`,`albums`.`timestamp`, `albums`.`name`, LEFT(albums.description, 50) as description, COUNT(images.image_id) as image_count
    FROM `albums`
    LEFT JOIN `images` ON `albums`.`album_id` = `images`.`album_id`
    WHERE `albums`.`user_id` = '{$user_id}'
    GROUP BY `albums`.`album_id`";
    $res = mysql_query($albums_query) or die(mysql_error().'<br>'.$albums_query);

    while($albums_row = mysql_fetch_assoc($res)){
    $albums [] = array (

    'id' => $albums_row['album_id'],
    'timestamp'=> $albums_row['timestamp'],
    'name' => $albums_row['name'],
    'description' => $albums_row['description'],
    'count' =>$albums_row['image_count']



    );

    }

    return $albums;

    }

    ?>

    <?php
    $user_id = $_SESSION['user_id'];
    $albums = get_albums($user_id);
    if(empty($albums)) {
    echo'<p>You don\'t have any albums</p>';
    }else{
    foreach($albums as $album){
    echo'<p><a href="view_album.php?album_id=', $album['id'], '">', $album['name'] ,'</a>
    (',$album['count'],' images)<br />', $album['description'],'...<br />
    <a href="edit_album.php?album_id=', $album['id'] ,'">Edit / </a><a href="delete_album.php?album_id=',$album['id'],'">Delete</a>
    </p>';
    }
    }

    ?>
  8. #5
  9. Known to taste like chicken
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    In front of my computer
    Posts
    399
    Rep Power
    312
    have you read what badger_fruit said?

    i suggest that you read his reply and then try again.
    "Take thy beak from out my heart, and take thy form from off my door" - Homer J Simpson / Edgar Allan Poe

    Looking for a project Idea?

IMN logo majestic logo threadwatch logo seochat tools logo