SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Deleting database entries

    I'm trying to adapt the code from the "jokes tutorial" to delete profiles from my database.

    I'd like to delete ALL of that players info from the database but I'm having trouble with the code.

    The way I have it now is like this:

    On the Barracks page (for admins) there is a table that lists all the members of our team. At the end of that there are options to Edit, Update, or Delete those players. But I Don't want just one accidental click to erase the profile so here's what I did.

    When you click the link "Delete" for that player it takes you to another page using the url like this

    "profiledelete.php?playername=Smokey"

    Here's the code from profiledelete.php
    PHP Code:
    <?php

    /************************************************************************/
    /* PHP-NUKE: Web Portal System                                          */
    /* ===========================                                          */
    /*                                                                      */
    /* Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)         */
    /* h*tp://phpnuke.org                                                   */
    /*                                                                      */
    /* This program is free software. You can redistribute it and/or modify */
    /* it under the terms of the GNU General Public License as published by */
    /* the Free Software Foundation; either version 2 of the License.       */
    /************************************************************************/

    if(!IsSet($mainfile)) { include ("mainfile.php"); }
        include (
    "header.php");    
            
    if (
    "Delete Player" == $deleteplayer) { 
        
    $sql "DELETE FROM player_profile " 
        
    "WHERE playername=$playername";
        
    if (
    mysql_query($sql)) {
        echo(
    "<P>Your profile has been deleted.</P>"); 
        } else {
        echo(
    "<P>Error deleting profile: " 
        
    mysql_error() . "</P>"); }}
    ?>

    <table width="99%" border="1" cellspacing="0" cellpadding="0" bordercolor="#003300">
      <tr>
        <td bgcolor="#003300">Confirm Deletion</td>
      </tr>
      <tr>
        <td align="center"> 
          <p>&nbsp;</p>
          <p>Are you sure you want to delete the player 
            "<?php echo ("$playername"); ?>"
            From the Roster?</p>
            <FORM ACTION="<?php echo($PHP_SELF); ?>"  METHOD="POST">
            <input type="submit" name="deleteplayer" value="Delete Player">
          </form>
          <p>&nbsp;</p>
        </td>
      </tr>
    </table>

    <?php
    include ("footer.php");
    ?>
    When this is run I get the error "Error deleting profile: You have an error in your SQL syntax near '' at line 1"

    What's wrong with this code?

    Can you help please? TIA
    Last edited by whofarted; Sep 4, 2001 at 14:30.
    You smell something?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When using anything but numbers in a where clause you must enclose it in quotes.

    PHP Code:
    if ("Delete Player" == $deleteplayer) { 
        
    $sql "DELETE FROM player_profile " 
        
    "WHERE playername=$playername"
    Should be

    PHP Code:
    if ("Delete Player" == $deleteplayer) { 
        
    $sql "DELETE FROM player_profile 
        WHERE playername='
    $playername'"
    Also you don't need to conatenate lines together cause PHP ignores whitespace.

    You can easily debug your query by putting

    echo $sql; in the script and then copy and paster the query to your commandline mysql interface or phpMyAdmin.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help man that was fast!

    Now I've got a new problem. It says it deleted it but I've checked the ddatabase & the other pages that use that info & it's still there??

    Why didn't it delete?

    I did that

    echo $sql;

    in ther & this came up:
    DELETE FROM player_profile WHERE playername=''

    Does that mean $playername has no value? I'm still a newbie, sorry
    You smell something?

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes since this is a confirmation page you'll need to repass the $plpayername back to the page when the form is submitted. Nothing a hidden input can't take care of.


    PHP Code:
            <FORM ACTION="<?php echo($PHP_SELF); ?>"  METHOD="POST">
            <input type="submit" name="deleteplayer" value="Delete Player">
          </form>
    to

    PHP Code:
            <FORM ACTION="<?php echo($PHP_SELF); ?>"  METHOD="POST">
            <input type="submit" name="deleteplayer" value="Delete Player">
    <input type="hidden" name="playername" value="<?=$playername?>">
          </form>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! Works like a charm!
    You smell something?

  6. #6
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just out of curiousity, How would I make the part about "are you sure you want to delete (playername) from the roster?" & the botton go away and only display the part that says "Your profile has been deleted." in it's place so noone will keep trying to delete the same person.

    Also, is it possible to redirect them after a few seconds back to the admin page? Of course providing A link to it incase there browser doesn't auto forward them.
    Here's the current version of the code if you need it:
    PHP Code:
    <?php

    /************************************************************************/
    /* PHP-NUKE: Web Portal System                                          */
    /* ===========================                                          */
    /*                                                                      */
    /* Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)         */
    /* h*tp://phpnuke.org                                                   */
    /*                                                                      */
    /* This program is free software. You can redistribute it and/or modify */
    /* it under the terms of the GNU General Public License as published by */
    /* the Free Software Foundation; either version 2 of the License.       */
    /************************************************************************/

    if(!IsSet($mainfile)) { include ("mainfile.php"); }
        include (
    "header.php");    
            
    if (
    "Delete Player" == $deleteplayer) { 
        
    $sql "DELETE FROM player_profile 
        WHERE playername='
    $playername'";

            
    if (
    mysql_query($sql)) {
        echo(
    "<P>Your profile has been deleted.</P>"); 
        } else {
        echo(
    "<P>Error deleting profile: " 
        
    mysql_error() . "</P>"); }}
    ?>

    <table width="99%" border="1" cellspacing="0" cellpadding="0" bordercolor="#003300">
      <tr>
        <td bgcolor="#003300">Confirm Deletion</td>
      </tr>
      <tr>
        <td align="center"> 
          <p>&nbsp;</p>
          <p>Are you sure you want to delete the player 
            "<?php echo ("$playername"); ?>"
            From the Roster?</p>

            <FORM ACTION="<?php echo($PHP_SELF); ?>"  METHOD="POST">
            <input type="submit" name="deleteplayer" value="Delete Player">
    <input type="hidden" name="playername" value="<?=$playername?>">
          </form>

          <p>&nbsp;</p>
        </td>
      </tr>
    </table>

    <?php
    include ("footer.php");
    ?>

    Ain't I just full of questions
    Last edited by whofarted; Sep 4, 2001 at 15:53.
    You smell something?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •