SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Oct 2001
    Location
    Half Moon Bay, CA
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why won't this script delete?

    Hey All,

    I can't for the life of me figure out why this script won't delete an entry. When I click the delete link, I receive the message that entry has been deleted, but a check of the mysql table shows it still being there. Can anyone help?

    Here is the code:

    PHP Code:
            <?php
        
    //Define Global Variables
        
    $PHP_SELF $_SERVER['PHP_SELF'];
        
        
    $submittask $_POST['submittask'];
        
    $brand $_POST['brand'];
        
    $item $_POST['item'];
        
    $size $_POST['size'];
        
    $color $_POST['color'];
        
    $imgloc $_POST['imgloc'];
        
    $imgname $_POST['imgname'];
        
    $request $_POST['request'];
        
    $category $_POST['category'];
        
    $comments $_POST['comments'];
        
    $ID $_POST['ID'];
        
    $deletetask $_POST['deletetask'];
        

         if (isset(
    $_REQUEST['addtask'])): // If the user wants to add a task
        
    ?>
        <form action="<? echo $PHP_SELF ?>" method="post">
            <table width="100%">
              <tr id="grey"> 
                <td id="leftcolumn">Type Of Request</td>
                <td><select name="request">
                    <option selected="selected">Type of Request</option>
                    <option value="addproduct">Add New Product</option>
                    <option value="changestatus">Change Status</option>
                    <option value="removeproduct">Remove Product</option>
                  </select></td>
              </tr>
              <tr> 
                <td id="leftcolumn">Category: </td>
                <td><select name="category">
                    <option selected="selected">Choose A Category</option>
                    <option value="Shoes">Shoes</option>
                    <option value="Decks">Decks</option>
                    <option value="Trucks">Trucks</option>
                    <option value="Wheels">Wheels</option>
                    <option value="Apparel">Apparel</option>
                    <option value="Bags">Bags</option>
                    <option value="Acessories">Accessories</option>
                    <option value="Videos">Videos</option>
                    <option value="FTC">FTC</option>
                    <option value="Blowout">Blowout</option>
                  </select></td>
              </tr>
              <tr id="grey"> 
                <td id="leftcolumn">Brand:</td>
                <td><input name="brand" type="text" />
                  (ex. </td>
              </tr>
              <tr> 
                <td id="leftcolumn">Item:</td>
                <td><input name="item" type="text" /></td>
              </tr>
              <tr id="grey"> 
                <td id="leftcolumn">Size:</td>
                <td><input name="size" type="text" /></td>
              </tr>
              <tr> 
                <td id="leftcolumn">Color:</td>
                <td><input name="color" type="text" /></td>
              </tr>
              <tr id="grey"> 
                <td id="leftcolumn">Image Location</td>
                <td><input name="imgloc" type="text" /></td>
              </tr>
              <tr> 
                <td id="leftcolumn">Image Filename:</td>
                <td><input name="imgname" type="text" id="imgname" /></td>
              </tr>
              <tr id="grey"> 
                <td id="leftcolumn">Additional Comments:</td>
                <td><textarea name="comments" cols="40" rows="10"></textarea></td>
              </tr>
              <tr id="grey"> 
                <td id="leftcolumn"><input type="submit" name="submittask" value="SUBMIT" /></td>
                <td>&nbsp;</td>
              </tr>
            </table>
          </form>
          
            <?php
            
    else: // Default page display
            
            // Connect to the database server
            
    $dbcnx = @mysql_connect("localhost""root""********");
            if (!
    $dbcnx) {
            echo( 
    "<p>Unable to connect to the database server at this time.</p>" );
            exit();
            }
            
            
    // Select the news database
            
    if (! @mysql_select_db("test") ) {
            echo( 
    "<p>Unable to locate the database at this time.</p>" );
            exit();
            }
            
            
    // If a story has been submitted,
            // add it to the database.
            
    if ($submittask == "SUBMIT") {
            
    $sql "INSERT INTO tasks SET
                    brand='
    $brand',
                    item='
    $item',
                    size='
    $size',
                    color='
    $color',
                    imgloc='
    $imgloc',
                    imgname='
    $imgname',
                    taskDate=CURDATE(),
                    request='
    $request',
                    category='
    $category',
                    comments='
    $comments'";
                  
            if (@
    mysql_query($sql)) {
            echo(
    "<p>Your task has been added.</p>");
            } else {
            echo(
    "<p>Error adding submitted task: " .
                 
    mysql_error() . "</p>");
              }
            }
            
            
    //If A Task Has Been Deleted
            
    if (isset($_REQUEST['deletetask'])) {
                
    $sql "DELETE FROM tasks WHERE ID='$taskid'";
                if (@
    mysql_query ($sql) ) {
                    echo (
    "<p>Task Has Been Deleted.</p>");
                }
                else {
                    echo (
    "<p>Error Deleting Task. Please Try Again.</p>");
                }
            }
            
            echo(
    "<p> Here are all the requests in our database: </p>");
            
            
    // Request the text of all the stories
            
    $result = @mysql_query("SELECT ID, category, item, request FROM tasks");
            if (!
    $result) {
            echo(
    "<p>Error performing query: " mysql_error() . "</p>");
            exit();
            }
            
            
    // Display the text of each story in a paragraph
            
    echo ("<table width='90%'>");
            echo (
    "<tr bgcolor='#999999'> 
                    <td width='10%'><div align='center'><font color='#FFFFFF'><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Task ID</font></strong></font></div></td>
                    <td width='20%'><div align='center'><font color='#FFFFFF'><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Category</font></strong></font></div></td>
                    <td width='30%'><div align='center'><font color='#FFFFFF'><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Item</font></strong></font></div></td>
                    <td width='20%'><div align='center'><font color='#FFFFFF'><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Type</font></strong></font></div></td>
                    <td width='20%'><div align='center'><font color='#FFFFFF'><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Remove</font></strong></font></div></td>
                     </tr>"
    );
            while ( 
    $row mysql_fetch_array($result) ) { 
            
    $taskid $row["ID"];
            
    //End PHP ?>
            
                    <tr>
                        <td align="center"><? echo ( $row['ID'] ); ?></td>
                        <td align="center"><? echo ( $row['category'] ); ?></td>
                        <td align="center"><? echo ( $row['item'] ); ?></td>
                        <td align="center"><? echo ( $row['request'] ); ?></td>
                        <td align="center"><? echo ("<a href='$PHP_SELF?deletetask=$taskid'>delete task</a></td>");?>
                    </tr>
            <?
            
    }
            echo (
    "</table>");
            
            
    // When clicked, this link will load this page
            // with the news submission form displayed.
            
    echo("<p><a href=$PHP_SELF?addtask=1>Add a New Task</a></p>");
            
            endif;
            
            
    ?>
    As always, thanks for the help...

  2. #2
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not having a lot of luck with this scipt are we? And you didn't heed my advice about printing out the variables and queries did you?

    Your link to the delete page:

    PHP Code:
    <? echo ("<a href='$PHP_SELF?deletetask=$taskid'>delete task</a></td>");?>
    Sets the var 'deletetask' to the the value of $taskid.

    Then on the reloading of the page, you try to set $taskid = $_POST['ID']. This 'ID' variable never exists.

    Try this:

    PHP Code:
         <?php 
        
    //Define Global Variables 
        
    $PHP_SELF $_SERVER['PHP_SELF']; 
         
        
    $submittask $_POST['submittask']; 
        
    $brand $_POST['brand']; 
        
    $item $_POST['item']; 
        
    $size $_POST['size']; 
        
    $color $_POST['color']; 
        
    $imgloc $_POST['imgloc']; 
        
    $imgname $_POST['imgname']; 
        
    $request $_POST['request']; 
        
    $category $_POST['category']; 
        
    $comments $_POST['comments']; 
        
    $taskid $_GET['deletetask']; 
         

        if (isset(
    $_REQUEST['addtask'])): // If the user wants to add a task 
        
    ?> 
        <form action="<? echo $PHP_SELF ?>" method="post"> 
            <table width="100%"> 
              <tr id="grey"> 
                <td id="leftcolumn">Type Of Request</td> 
                <td><select name="request"> 
                    <option selected="selected">Type of Request</option> 
                    <option value="addproduct">Add New Product</option> 
                    <option value="changestatus">Change Status</option> 
                    <option value="removeproduct">Remove Product</option> 
                  </select></td> 
              </tr> 
              <tr> 
                <td id="leftcolumn">Category: </td> 
                <td><select name="category"> 
                    <option selected="selected">Choose A Category</option> 
                    <option value="Shoes">Shoes</option> 
                    <option value="Decks">Decks</option> 
                    <option value="Trucks">Trucks</option> 
                    <option value="Wheels">Wheels</option> 
                    <option value="Apparel">Apparel</option> 
                    <option value="Bags">Bags</option> 
                    <option value="Acessories">Accessories</option> 
                    <option value="Videos">Videos</option> 
                    <option value="FTC">FTC</option> 
                    <option value="Blowout">Blowout</option> 
                  </select></td> 
              </tr> 
              <tr id="grey"> 
                <td id="leftcolumn">Brand:</td> 
                <td><input name="brand" type="text" /> 
                  (ex. </td> 
              </tr> 
              <tr> 
                <td id="leftcolumn">Item:</td> 
                <td><input name="item" type="text" /></td> 
              </tr> 
              <tr id="grey"> 
                <td id="leftcolumn">Size:</td> 
                <td><input name="size" type="text" /></td> 
              </tr> 
              <tr> 
                <td id="leftcolumn">Color:</td> 
                <td><input name="color" type="text" /></td> 
              </tr> 
              <tr id="grey"> 
                <td id="leftcolumn">Image Location</td> 
                <td><input name="imgloc" type="text" /></td> 
              </tr> 
              <tr> 
                <td id="leftcolumn">Image Filename:</td> 
                <td><input name="imgname" type="text" id="imgname" /></td> 
              </tr> 
              <tr id="grey"> 
                <td id="leftcolumn">Additional Comments:</td> 
                <td><textarea name="comments" cols="40" rows="10"></textarea></td> 
              </tr> 
              <tr id="grey"> 
                <td id="leftcolumn"><input type="submit" name="submittask" value="SUBMIT" /></td> 
                <td>&nbsp;</td> 
              </tr> 
            </table> 
          </form> 
           
            <?php 
            
    else: // Default page display 
             
            // Connect to the database server 
            
    $dbcnx = @mysql_connect("localhost""root""********"); 
            if (!
    $dbcnx) { 
            echo( 
    "<p>Unable to connect to the database server at this time.</p>" ); 
            exit(); 
            } 
             
            
    // Select the news database 
            
    if (! @mysql_select_db("test") ) { 
            echo( 
    "<p>Unable to locate the database at this time.</p>" ); 
            exit(); 
            } 
             
            
    // If a story has been submitted, 
            // add it to the database. 
            
    if ($submittask == "SUBMIT") { 
            
    $sql "INSERT INTO tasks SET 
                    brand='
    $brand', 
                    item='
    $item', 
                    size='
    $size', 
                    color='
    $color', 
                    imgloc='
    $imgloc', 
                    imgname='
    $imgname', 
                    taskDate=CURDATE(), 
                    request='
    $request', 
                    category='
    $category', 
                    comments='
    $comments'"
                   
            if (@
    mysql_query($sql)) { 
            echo(
    "<p>Your task has been added.</p>"); 
            } else { 
            echo(
    "<p>Error adding submitted task: " 
                 
    mysql_error() . "</p>"); 
              } 
            } 
             
            
    //If A Task Has Been Deleted 
            
    if (isset($_REQUEST['deletetask'])) { 
                
    $sql "DELETE FROM tasks WHERE ID=$taskid"
                if (@
    mysql_query ($sql) ) { 
                    echo (
    "<p>Task Has Been Deleted.</p>"); 
                } 
                else { 
                    echo (
    "<p>Error Deleting Task. Please Try Again.</p>"); 
                } 
            } 
             
            echo(
    "<p> Here are all the requests in our database: </p>"); 
             
            
    // Request the text of all the stories 
            
    $result = @mysql_query("SELECT ID, category, item, request FROM tasks"); 
            if (!
    $result) { 
            echo(
    "<p>Error performing query: " mysql_error() . "</p>"); 
            exit(); 
            } 
             
            
    // Display the text of each story in a paragraph 
            
    echo ("<table width='90%'>"); 
            echo (
    "<tr bgcolor='#999999'> 
                    <td width='10%'><div align='center'><font color='#FFFFFF'><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Task ID</font></strong></font></div></td> 
                    <td width='20%'><div align='center'><font color='#FFFFFF'><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Category</font></strong></font></div></td> 
                    <td width='30%'><div align='center'><font color='#FFFFFF'><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Item</font></strong></font></div></td> 
                    <td width='20%'><div align='center'><font color='#FFFFFF'><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Type</font></strong></font></div></td> 
                    <td width='20%'><div align='center'><font color='#FFFFFF'><strong><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>Remove</font></strong></font></div></td> 
                     </tr>"
    ); 
            while ( 
    $row mysql_fetch_array($result) ) {  
            
    $taskid $row["ID"]; 
            
    //End PHP ?> 
             
                    <tr> 
                        <td align="center"><? echo ( $row['ID'] ); ?></td> 
                        <td align="center"><? echo ( $row['category'] ); ?></td> 
                        <td align="center"><? echo ( $row['item'] ); ?></td> 
                        <td align="center"><? echo ( $row['request'] ); ?></td> 
                        <td align="center"><? echo ("<a href='$PHP_SELF?deletetask=$taskid'>delete task</a></td>");?> 
                    </tr> 
            <? 
            

            echo (
    "</table>"); 
             
            
    // When clicked, this link will load this page 
            // with the news submission form displayed. 
            
    echo("<p><a href=$PHP_SELF?addtask=1>Add a New Task</a></p>"); 
             
            endif; 
             
            
    ?>

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2001
    Location
    Half Moon Bay, CA
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mincer!!

    That worked perfectly!!

    You know, I tried the printing out the variables but didn't really get it. Could you give me an example? I really appreciate your help, this is what happens when someone with a design background tries to code.

    Also, I posted another thread regarding this little task manager I'm building. I have a column for 'status' that I'd like to set to "unprocessed" as soon as a task is submitted. Then, from an admin page for developers (me), I want to be able to change that status (processed, unprocessed, in-process) via a drop down menu. How would I pull in these values to a drop-down and have the current status being the one selected? If you could offer any insight into this I might even be able to go home from work early.

    Again thanks, I really appreciate it. . .


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
  •