mysql and php5 deleting rows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew M.

    mysql and php5 deleting rows

    I can't seem to delete rows from a mysql database. I have a database
    that I want to delete rows from based on user name. i have researched
    this extensively and can't seem to find anything that works. Any help is
    greatly appreciated.
  • News Me

    #2
    Re: mysql and php5 deleting rows

    Andrew M. wrote:[color=blue]
    > I can't seem to delete rows from a mysql database. I have a database
    > that I want to delete rows from based on user name. i have researched
    > this extensively and can't seem to find anything that works. Any help is
    > greatly appreciated.[/color]

    What have you tried so far?

    NM

    --
    convert uppercase WORDS to single keystrokes to reply

    Comment

    • Andrew M.

      #3
      Re: mysql and php5 deleting rows



      News Me wrote:
      [color=blue]
      > Andrew M. wrote:
      >[color=green]
      >> I can't seem to delete rows from a mysql database. I have a database
      >> that I want to delete rows from based on user name. i have researched
      >> this extensively and can't seem to find anything that works. Any help
      >> is greatly appreciated.[/color]
      >
      >
      > What have you tried so far?
      >
      > NM
      >[/color]
      Here is what i have been trying to get working.

      <?php

      //Connect to ple_security
      $conn = mysql_connect( "localhost" , "ple_securi ty", "blah" )
      or die ( "Unable to Connect" );

      #select the database
      $rs = mysql_select_db ( "ple_securi ty", $conn )
      or die( "Could not select database" );

      //create the query
      //$sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_d elete\'";

      //execute query
      mysql_query ("DELETE FROM users WHERE user_name = $user_name_dele te");

      ?>

      THANKS in advance for any help. I know that this is problem a newbie
      problem.

      Comment

      • Geoff Berrow

        #4
        Re: mysql and php5 deleting rows

        I noticed that Message-ID: <5qeId.158387$U f.12949@twister .nyroc.rr.com>
        from Andrew M. contained the following:

        I assume you are connecting to the database ok
        [color=blue]
        >//create the query
        >//$sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_d elete\'";[/color]
        This line is redundant[color=blue]
        >
        >//execute query
        >mysql_query ("DELETE FROM users WHERE user_name = $user_name_dele te");[/color]
        Should work, provided $user_name_dele te actually contains something.
        Where does it come from?

        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • CJ Llewellyn

          #5
          Re: mysql and php5 deleting rows

          "Andrew M." <andrewm_nospam @rochester.rr.c om> wrote in message
          news:5qeId.1583 87$Uf.12949@twi ster.nyroc.rr.c om...[color=blue]
          >
          >
          > News Me wrote:
          >[color=green]
          > > Andrew M. wrote:
          > >[color=darkred]
          > >> I can't seem to delete rows from a mysql database. I have a database
          > >> that I want to delete rows from based on user name. i have researched
          > >> this extensively and can't seem to find anything that works. Any help
          > >> is greatly appreciated.[/color]
          > >
          > >
          > > What have you tried so far?
          > >
          > > NM
          > >[/color]
          > Here is what i have been trying to get working.
          >
          > <?php
          >
          > //Connect to ple_security
          > $conn = mysql_connect( "localhost" , "ple_securi ty", "blah" )
          > or die ( "Unable to Connect" );
          >
          > #select the database
          > $rs = mysql_select_db ( "ple_securi ty", $conn )
          > or die( "Could not select database" );
          >
          > //create the query
          > //$sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_d elete\'";
          >
          > //execute query
          > mysql_query ("DELETE FROM users WHERE user_name = $user_name_dele te");
          >
          > ?>
          >
          > THANKS in advance for any help. I know that this is problem a newbie
          > problem.[/color]

          $sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_d elete\'";
          $result = mysql_query($sq l, $conn);
          if(! $result || mysql_error($co nn))
          {
          eho "Unable to delete user [$sql] : " . mysql_error($co nn);
          }

          Always formulate your SQL quiries into a string, that way you can see what
          you are asking the database to do.

          Always test IO (input/output) operations for errors.

          You should see where your query is wrong.

          $sql = "DELETE FROM users WHERE user_name = '$user_name_del ete'";

          Note that this is prone to abuse (SQL injection) so if you've not got magic
          quotes switched on you'll have to escape the $user_name_dele te variable.

          $sql = sprintf("DELETE FROM users WHERE user_name = '%s'",
          addslashes($use r_name_delete)) ;



          Comment

          • Andrew M.

            #6
            Re: mysql and php5 deleting rows



            CJ Llewellyn wrote:
            [color=blue]
            > "Andrew M." <andrewm_nospam @rochester.rr.c om> wrote in message
            > news:5qeId.1583 87$Uf.12949@twi ster.nyroc.rr.c om...
            >[color=green]
            >>
            >>News Me wrote:
            >>
            >>[color=darkred]
            >>>Andrew M. wrote:
            >>>
            >>>
            >>>>I can't seem to delete rows from a mysql database. I have a database
            >>>>that I want to delete rows from based on user name. i have researched
            >>>>this extensively and can't seem to find anything that works. Any help
            >>>>is greatly appreciated.
            >>>
            >>>
            >>>What have you tried so far?
            >>>
            >>>NM
            >>>[/color]
            >>
            >>Here is what i have been trying to get working.
            >>
            >><?php
            >>
            >>//Connect to ple_security
            >>$conn = mysql_connect( "localhost" , "ple_securi ty", "blah" )
            >>or die ( "Unable to Connect" );
            >>
            >>#select the database
            >>$rs = mysql_select_db ( "ple_securi ty", $conn )
            >>or die( "Could not select database" );
            >>
            >>//create the query
            >>//$sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_d elete\'";
            >>
            >>//execute query
            >>mysql_query ("DELETE FROM users WHERE user_name = $user_name_dele te");
            >>
            >>?>
            >>
            >>THANKS in advance for any help. I know that this is problem a newbie
            >>problem.[/color]
            >
            >
            > $sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_d elete\'";
            > $result = mysql_query($sq l, $conn);
            > if(! $result || mysql_error($co nn))
            > {
            > eho "Unable to delete user [$sql] : " . mysql_error($co nn);
            > }
            >
            > Always formulate your SQL quiries into a string, that way you can see what
            > you are asking the database to do.
            >
            > Always test IO (input/output) operations for errors.
            >
            > You should see where your query is wrong.
            >
            > $sql = "DELETE FROM users WHERE user_name = '$user_name_del ete'";
            >
            > Note that this is prone to abuse (SQL injection) so if you've not got magic
            > quotes switched on you'll have to escape the $user_name_dele te variable.
            >
            > $sql = sprintf("DELETE FROM users WHERE user_name = '%s'",
            > addslashes($use r_name_delete)) ;[/color]

            Thank you very much. That's the ticket.

            Comment

            • Andrew M.

              #7
              Re: mysql and php5 deleting rows



              Geoff Berrow wrote:
              [color=blue]
              > I noticed that Message-ID: <5qeId.158387$U f.12949@twister .nyroc.rr.com>
              > from Andrew M. contained the following:
              >
              > I assume you are connecting to the database ok
              >
              >[color=green]
              >>//create the query
              >>//$sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_d elete\'";[/color]
              >
              > This line is redundant
              >[color=green]
              >>//execute query
              >>mysql_query ("DELETE FROM users WHERE user_name = $user_name_dele te");[/color]
              >
              > Should work, provided $user_name_dele te actually contains something.
              > Where does it come from?
              >[/color]
              My problem was fixed as soon as I made it = '$user_name_del ete' ");

              Thanks for all the help.

              Comment

              Working...