Jump to content


Photo

PHP Deleting Records


  • Please log in to reply
5 replies to this topic

#1 gfX

gfX
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 25 June 2006 - 05:33 PM

I have an image hosting script here - and this is in the admin.php file. It will list all the registered users and then I click "Edit Details" and here is the script for that:

<fieldset class="fi">
    <legend>Basic Details</legend>
        <?php
            if($_POST['basic']) {
                if($_POST['password'] !== "") 
                    $pass = md5($_POST['password']);
                }else{
                    $pass = $_POST['password'];
                @mysql_query("UPDATE users SET nickname='$_POST[nickname]', password='$pass', email='$_POST[email]' WHERE nickname='$_GET[user]'");
                echo "<h2>Updated</h2>";
            }
        ?>
        <form name="basic" action="admin.php?request=users&user=<?=$var['nickname']; ?>&act=do" method="post">
        <b>Username</b>: <input class="text" name="nickname" size="40" value="<?=$var['nickname']; ?>"><br />
        <b>Edit Password</b>: <input class="text" name="password" size="40" value=""><br />
        <b>Email</b>: <input class="text" name="email" size="40" value="<?=$var['email']; ?>">
        <input type="submit" name="basic">
        </form>
</fieldset>    

But that script keeps messing up. When I click Edit details - It goes to that page but it already has the heading "Updated" and the values are there - and then when I click submit it updates the record in the database to nothing. Blank.
So when I go to edit the user, it wont let me because all the values and username are ""
and I have to keep restoring in the database.

So I don't get to edit anything, whenever I click Edit Details for the user - it updates just when I go to the page and it won't let me update.

Anyone see anything wrong with teh code?

Thanks

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 June 2006 - 05:46 PM

look at your if statement. "if the posted password does not equal "" encrypt it. Otherwise, update the database." Does that make sense to you? Your if statement should be something like this: "if the posted password does not equal "", encrypt it and update the database. Otherwise, spit out a "no password given error".

But what would be even better, would be to check to make sure that a) password is also set, not just not equal to "", and also check to make sure nickname and email is also set.

      <?php
            if($_POST['basic']) {
                if($_POST['password'] !== "")
                    $pass = md5($_POST['password']);
                }else{
                    $pass = $_POST['password'];
                @mysql_query("UPDATE users SET nickname='$_POST[nickname]', password='$pass', email='$_POST[email]' WHERE nickname='$_GET[user]'");
                echo "<h2>Updated</h2>";
            }
        ?>

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 gfX

gfX
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 25 June 2006 - 05:59 PM

Well if they didn't put a password - it would still be the old one. Because this is for admins, and what if they just want to update the users e-mail address.

And even if I edit that stuff, The page still messes up. It says "UPDATED" just when I go to that page and clears that record in the database with blanks.

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 June 2006 - 06:11 PM

you aren't listening. look at your if statements. verbally say them. the only way your query is going to run is if $_POST['password'] equals "" in other words, nothing. The only thing your if statemend DOES do is if someone enters something in the password field, it encrypts it. Nothing else. No query update, no nothing.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 gfX

gfX
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 25 June 2006 - 06:31 PM

Alright, I understand. So can you give me the correct code for this script to work? I tryed and it still did the same thing for me. Weird


Thankss.

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 June 2006 - 04:43 AM

i told you how to write it in my previous post.
$password = $_POST['password'];
//if the user entered in a password...
if (isset($password) && trim($password) != '') {
  $password = md5($password);
  //update query here
} else {
  //if they did not enter in a password, do this...
  //or don't have an else, if you don't want it 
  //to do anything if they did not enter a pw in
}

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users