SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    Non-Member bronze trophy geniusgoalie's Avatar
    Join Date
    Sep 2004
    Location
    Buffalo, USA
    Posts
    979
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    won't delete the row!

    This seems very textbook, but it isn't working. Once I carry over the variables (which it does do correctly) the delete query doesn't work. Anyone know why this may be? (NOTE: This is a small snippet, the actual code is much longer, so I really didn't forget the $connect variable or <?php)
    PHP Code:
    if(isset($_POST['submit'])){
                     // Get linkid from url
                     $linkid = $_GET['linkid'];
                     // Delete the link
                     $result=mysql_query("DELETE FROM links WHERE linkid=$linkid ",$connect);
                     echo "<font size=5 color=red><b>Record Deleted!</b></font><br>
                           <font size=2>You will now be redirected to the Main Page in 3 seconds</font><br><br>";
                  include "footer.php";
                     echo "<meta http-equiv=Refresh content=3;url=index.php>";
                   }
           // If form not being submited... well then display the thing
           else{
                ?>
                <table width='100%'>
                 <tr>
                  <td colspan='2'><center>
                  <font color='red' size='5'><b>Are you sure you want to delete<br>
                  the link to</font><font size='5'> <?php echo $name?>?</b></font>
                  </td>
                 </tr>
                 <tr>
                  <td align='right' width='35%'>
                   <form method="post" action="<?php echo $PHP_SELF ?>">
                    <input style='font-weight: bold; font-size: x-small;color: #FFFFFF;background-color:RED;letter-spacing:1px;height:20px;border-style:solid;border-width:1px;border-color :#000000;' type="submit" name="submit" value="   YES   ">&nbsp;&nbsp;
                   </form>
                  </td>
                  <td align='left' width='65%'>
                   <form method="post" action="index.php">
                    &nbsp;&nbsp;<input style='font-weight: bold; font-size: x-small;color: #FFFFFF;background-color:green;letter-spacing:1px;height:20px;border-style:solid;border-width:1px;border-color :#000000;' type="submit" name="submit" value="               NO             ">

                   </form>
                  </td>
                 </tr>
                </table>

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i know you said that you connected but did you select the databaseu need??
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another thing ive just seen, when u have this line:

    PHP Code:
    $result=mysql_query("DELETE FROM links WHERE linkid=$linkid ",$connect); 
    doesnt the $connect point towards the connection not the database that you have selected, i would have thought that the if your going to put a variable in there it would need to be the one for the database you have selected??
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe try this:
    PHP Code:

    $linkid 
    '\'' mysql_real_escape_string($_GET['linkid']) . '\''
        
        
    $sql 'DELETE'
            
    .    ' FROM'
            
    .    ' links' 
            
    .    ' WHERE'
            
    .    ' linkid = ' $linkid 
            
    ;
           
           
    $result mysql_query($sql) or die (mysql_error); 
    Lookint at it aswell, do u need to "specify what you are deleting" FROM links, i dont know whether you do or not might be worth tryin
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  5. #5
    Non-Member bronze trophy geniusgoalie's Avatar
    Join Date
    Sep 2004
    Location
    Buffalo, USA
    Posts
    979
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried all of the advice you gave me (and added a deletion wildcard, maybe not such a good idea but I'm a bit desperate) but it didnt work. And the connection works fine in everything else.
    thanks for trying, though
    Any other ideas?

  6. #6
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes 1 more idea, wait for someone more experienced than me to help

    Sorry couldnt be more help, but good luck anyways
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  7. #7
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $linkid = $_GET['linkid'];
    should probably be
    $linkid = $_POST['linkid'];

    Put the linkid in the form as a hidden input.

    $_SERVER['PHP_SELF'] will not include the get variables the way I think you're trying to do it.

  8. #8
    Non-Member bronze trophy geniusgoalie's Avatar
    Join Date
    Sep 2004
    Location
    Buffalo, USA
    Posts
    979
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by HardCoded
    $linkid = $_GET['linkid'];
    should probably be
    $linkid = $_POST['linkid'];

    Put the linkid in the form as a hidden input.

    $_SERVER['PHP_SELF'] will not include the get variables the way I think you're trying to do it.
    I tried that, and it still didn't work. What is happening is that it's passing the variable, but not using it in the mysql query. Hmmm...

  9. #9
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe you'd better repost what you have.

  10. #10
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    What about the quotes around you variable?
    PHP Code:
    $result=mysql_query("DELETE FROM links WHERE linkid='$linkid' ",$connect); 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  11. #11
    SitePoint Evangelist
    Join Date
    Feb 2004
    Location
    Sofia, Bulgaria
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so you're getting the link id through $_GET, but there is no link id in the URL on the page i think.. so you maybe should try this:

    PHP Code:
    <form method="post" action="<?php echo ($_SERVER['PHP_SELF'].'?linkid='.$_GET['linkid']); ?>">
    the other way is as HardCoded mentioned to use hidden field and to get the variable through $_POST:

    PHP Code:
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
      <input type="hidden" name="linkid" value="<?php echo $_GET['linkid']; ?>">
    ...and use $_POST['linkid'] to get the variable... and maybe put some data validation before execute delete statement, of course ;-)

  12. #12
    Non-Member bronze trophy geniusgoalie's Avatar
    Join Date
    Sep 2004
    Location
    Buffalo, USA
    Posts
    979
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh, thanks for everyones help. It still wasnt working, but I realized that it could be tied in with other features through sessions.
    Thanks!

  13. #13
    SitePoint Evangelist
    Join Date
    Feb 2004
    Location
    Sofia, Bulgaria
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    could you change your code this way and post debug information here..

    PHP Code:
    if (isset($_POST['submit'])) {
      
    // Get linkid from url 
      
    $linkid $_GET['linkid']; 
      
    // Delete the link 
      
    $query 'DELETE FROM links WHERE linkid='.$linkid;
      
    $result mysql_query($query$connect);
      
    $result2 mysql_query($query);
      echo 
    '<pre>';
      
    var_dump($linkid);
      
    var_dump($query);
      
    var_dump($result);
      
    var_dump($result2);
      
    var_dump(mysql_affected_rows($connect));
      
    var_dump(mysql_affected_rows());
      echo 
    '</pre>';
      echo 
    '
      echo "<font size=5 color=red><b>Record Deleted!</b></font><br><font size=2>You will now be redirected to the Main Page in 3 seconds</font><br><br>"; 
      include "footer.php"; 
      echo "<meta http-equiv=Refresh content=3;url=index.php>"; 


  14. #14
    Non-Member bronze trophy geniusgoalie's Avatar
    Join Date
    Sep 2004
    Location
    Buffalo, USA
    Posts
    979
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it working with sessions. Thanks for your help!

  15. #15
    SitePoint Evangelist
    Join Date
    Feb 2004
    Location
    Sofia, Bulgaria
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    session is very tricky, be careful with it.. take care to unset variable after you don't need it anymore, because the variables are kept in it until you unset it or destroy the session, so be sure that the variables are set where there are supposed to be, and are unset where you don't need them anymore..


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
  •