Jump to content

[SOLVED] Records managment with functions


SpireLink

Recommended Posts

Hi all,

i am working on a script which will allow me to add, list, update, and remove recordsfrom database

 

Untile now i was able to add, but i cant delete..

 

the code usage

 

ADD: base.php?crl=rank.php&do=add

LIST:base.php?crl=rank.php&do=modify

UPDATE:base.php?crl=rank.php&do=update&id=

DELETE: base.php?crl=rank.php&do=delete&id=

 

sorry, its rank.php not ranl.php

 

 

 

Thanks

 

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

rank.txt only contains two functions, add and remove. In order for  list and update to work you must add those functions in.

 

rank.txt calls either add, remove, update or list functions depending on what $_GET['do'] is set to.

 

Wide, i know that ..

The thing that the add works, but the remove is not working ..

i have used a java script to tell me that the remove was done, but it doesn't ...

 

Thanks

Link to comment
Share on other sites

Oh, I see. Maybe because your link is base.php?crl=rank.php&do=delete&id= and not base.php?crl=rank.php&do=remove&id=

 

 

Hi, I have done this

// START DELETE RANK
function remove ($id)
{
if (isset($HTTP_GET_VARS['id'])) {
  $rank_id = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['id'] : addslashes($HTTP_GET_VARS['id']);
}
include("../includes/config.php");
$remove="DELETE FROM ranks WHERE rank_id=$rank_id";
$remove_rank=mysql_query($remove,$db);
}
// END DELETE RANK

 

and changed the link to be

base.php?crl=rank.php&do=remove&id=3

 

but it's stell not removing that record ...

 

Link to comment
Share on other sites

Why are you retrieving the id from get in your function? The id already gets passed to the function from the code at the top of your script.

 

Change your function to:

// START DELETE RANK
function remove ($id)
{
    if (is_numeric($id)
    {
        include("../includes/config.php");

        $sql= "DELETE FROM ranks WHERE rank_id=$id";

        if(mysql_query($sql, $db))
        {
            echo 'Record deleted';
        }
        else
        {
            echo 'Unable to delete record!<br />Query: ' . $sql . '<br /><br />' . mysql_error($db);
        }
    }
    else
    {
        echo 'id must only be a number!';
    }
}
// END DELETE RANK

Link to comment
Share on other sites

thanks, it works like a charm even i have added the function that will show ma a list with the modify/delete link so i will be able to do it..

now the thing in that i cant update the data, it show me the current data but when i change any thing in there it doesnt update the record and show me an error message

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.