PHP experts .. please help!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gasper
    • Jul 2026

    #1

    PHP experts .. please help!!

    I'm trying to make a script to delete a row from a mysql table ......

    Can someone tell me what's wrong ??!?

    Please take a look on the last 7 lines .. without them it works (but the script is not complete)


    PHP Code:
    
    <form method="get" action="update.php"> 
    <?
    mysql_pconnect("localhost","username","password"); 
    mysql_select_db("databasename"); 
    if(!$submit)
    {
        $result = mysql_query("select * from poly_links order by id"); 
        while($r=mysql_fetch_array($result)) 
        { 
            
            $id=$r["id"];        
            $songname=$r["songname"];
            $author=$r["author"];
    
                    ?>
            <INPUT TYPE="RADIO" NAME="id" VALUE="<?php echo $id;?>"><br> 
            <?php echo $id;?> 
            <?php echo $songname;?>
            <?php echo $author;?><br> 
    <?
        }?>
    <input type="submit" value="submit" name="Submit"></form> 
    <?
    }?> 
    
    <?
    else
    {
        $sql = "DELETE FROM poly_links WHERE id=$id";
        $result = mysql_query($sql);
        echo "News Deleted.";
    }?>
  • grumpy
    Too lazy to set a custom title
    • Jan 2002
    • 9870

    #2
    $sql = "DELETE FROM poly_links WHERE id='$id';";
    $result = mysql_query($sql);


    Try this
    Don't let greediness blur your vision | You gotta let some shit slide
    icq - 441-456-888

    Comment

    • grumpy
      Too lazy to set a custom title
      • Jan 2002
      • 9870

      #3
      Does have $id a vaule??

      Just put on top

      print "id value :$id<br>\n";

      then you know it has a value..otherwise there is nothing to delete
      Don't let greediness blur your vision | You gotta let some shit slide
      icq - 441-456-888

      Comment

      • twitchkat
        Registered User
        • Apr 2003
        • 2

        #4
        Code:
        {
        
            $sql = "DELETE FROM poly_links WHERE id=$id";
        
            $result = mysql_query($sql);
        
            echo "News Deleted.";
        
        }
        I bet $id hasn't been defined when you set $sql.

        You can verify this by putting:

        Code:
        die("SQL QUERY: " . $sql);
        after the $sql assignment. If it resolves to:

        DELETE FROM poly_links WHERE id=

        then that's not valid SQL.

        Grumpy's quoting suggestion is good practice.

        Comment

        • apscripts
          Confirmed User
          • Mar 2003
          • 204

          #5
          The quoting isn't necessary for numeric characters, if the field id is in fact numeric. You should write a function to convert all your empty numeric values to NULL and to quote all your strings. A lot of people call these clean up functions, etc. Also mysql_query does not return anything on DELETE or INSERT. So there is no sense in setting $result to nothing

          I don't know what error you're getting, but chances are you have no value in $id as suggested previously.

          Also - I am *guessing* that I cannot see your entire script - but if that *is* the whole script, you need register_globals on...which is a very, very bad thing to do. register_globals if for pretend environments.
          icq5708193

          aptgp III -- Build a Blog, an RSS feed, a text TGP, and a thumb TGP all from one installation. Own Comus or AutoGallery? Have APTGP III Installed free for 30 days; no obligations.

          Comment

          Working...