Delete Script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mpar612@gmail.com

    Delete Script

    Hi everyone,

    I appreciate all of your help with me and the problems I have been
    having. I'm new to PHP and MySQL and I'm having some problems getting
    this script to work. I can't get this to work and I don't understand
    why. I don't get an error or anything, it almost seems like the page
    refreshes. I went to the phpmyadmin and the row is still in the
    database. The $_GET parts work perfectly in another script and the SQL
    statement works when I insert hard values in it. Any thoughts would be
    greatly appreciated. Thanks in advance.

    <form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>">
    <table>

    <tr><td colspan="2" align="center"> Yes <?php
    input_radiochec k('radio','yes_ no', $defaults, 'yes'); ?No <?php
    input_radiochec k('radio','yes_ no', $defaults, 'no'); ?>
    </td></tr>

    <tr><td colspan="2" align="center"> <?php input_submit('s ave','Add'); ?>
    </td></tr>

    </table>
    <input type="hidden" name="_submit_c heck" value="1"/>
    </form>

    <?php

    function process_form() {

    // Access the global variable $db inside this function
    global $db;

    $isbn = $_GET['isbn'];
    $artist_name = $_GET['artist_name'];
    $album_title = $_GET['album_title'];

    if ($_POST['yes_no'] == 'yes') {

    $delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
    \'$artist_name\ ' AND album_title = \'$album_title\ '";
    // Delete the record
    $db->query($delete_ sql);
    print "The record was deleted";
    } else {
    print "The record was not deleted";
    }
    }

    ?>

  • J.O. Aho

    #2
    Re: Delete Script

    mpar612@gmail.c om wrote:
    Hi everyone,
    >
    I appreciate all of your help with me and the problems I have been
    having. I'm new to PHP and MySQL and I'm having some problems getting
    this script to work. I can't get this to work and I don't understand
    why. I don't get an error or anything, it almost seems like the page
    refreshes. I went to the phpmyadmin and the row is still in the
    database. The $_GET parts work perfectly in another script and the SQL
    statement works when I insert hard values in it. Any thoughts would be
    greatly appreciated. Thanks in advance.
    <form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>">
    $isbn = $_GET['isbn'];
    $artist_name = $_GET['artist_name'];
    $album_title = $_GET['album_title'];
    The form method is POST, then
    $_GET['isbn']=$_GET['artist_name']=$_GET['album_title']=NULL
    use $_POST['isbn'], $_POST['artist_name'] and $_POST['album_title'].

    You can simplify your form tag, action="" is the same as calling itself, less
    code and less work for PHP if you use:

    <form method="POST" action="">

    $delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
    \'$artist_name\ ' AND album_title = \'$album_title\ '";
    $delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
    '$artist_name' AND album_title = '$album_title'" ;

    Remember that the column isbn has to be INT.



    //Aho

    Comment

    • mpar612

      #3
      Re: Delete Script


      J.O. Aho wrote:
      mpar612@gmail.c om wrote:
      Hi everyone,

      I appreciate all of your help with me and the problems I have been
      having. I'm new to PHP and MySQL and I'm having some problems getting
      this script to work. I can't get this to work and I don't understand
      why. I don't get an error or anything, it almost seems like the page
      refreshes. I went to the phpmyadmin and the row is still in the
      database. The $_GET parts work perfectly in another script and the SQL
      statement works when I insert hard values in it. Any thoughts would be
      greatly appreciated. Thanks in advance.
      >
      >
      <form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>">
      $isbn = $_GET['isbn'];
      $artist_name = $_GET['artist_name'];
      $album_title = $_GET['album_title'];
      >
      The form method is POST, then
      $_GET['isbn']=$_GET['artist_name']=$_GET['album_title']=NULL
      use $_POST['isbn'], $_POST['artist_name'] and $_POST['album_title'].
      >
      You can simplify your form tag, action="" is the same as calling itself, less
      code and less work for PHP if you use:
      >
      <form method="POST" action="">
      >
      >
      $delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
      \'$artist_name\ ' AND album_title = \'$album_title\ '";
      >
      $delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
      '$artist_name' AND album_title = '$album_title'" ;
      >
      Remember that the column isbn has to be INT.
      >
      >
      >
      //Aho
      Thanks! I should have mentioned that the following is required because
      they are being pulled form the url

      $isbn = $_GET['isbn'];
      $artist_name = $_GET['artist_name'];
      $album_title = $_GET['album_title'];
      I shouldn't use $_POST should I?

      Thanks!

      Comment

      • J.O. Aho

        #4
        Re: Delete Script

        mpar612 wrote:
        Thanks! I should have mentioned that the following is required because
        they are being pulled form the url
        https://www.domain.com/delete_record...&album_title=:
        When looking at your example you don't provide this data at all and to make
        things a lot easier I would include them into the form as hidden input-tags.
        Things gets a lot easier if you keep on sending data in the same way and not
        try to mix.


        //Aho

        Comment

        • mpar612

          #5
          Re: Delete Script


          J.O. Aho wrote:
          mpar612 wrote:
          >
          Thanks! I should have mentioned that the following is required because
          they are being pulled form the url
          https://www.domain.com/delete_record...&album_title=:
          >
          When looking at your example you don't provide this data at all and to make
          things a lot easier I would include them into the form as hidden input-tags.
          Things gets a lot easier if you keep on sending data in the same way and not
          try to mix.
          >
          >
          //Aho
          Thanks! Could you please elaborate a little bit more, I'm a beginner
          and I don't really understand what you are saying. I don't see how I
          am trying to mix the way that I am sending data.

          Thanks!

          Comment

          • J.O. Aho

            #6
            Re: Delete Script

            mpar612 wrote:
            J.O. Aho wrote:
            >mpar612 wrote:
            >>
            >>Thanks! I should have mentioned that the following is required because
            >>they are being pulled form the url
            >>https://www.domain.com/delete_record...&album_title=:
            >When looking at your example you don't provide this data at all and to make
            >things a lot easier I would include them into the form as hidden input-tags.
            >Things gets a lot easier if you keep on sending data in the same way and not
            >try to mix.
            >>
            >>
            > //Aho
            >
            Thanks! Could you please elaborate a little bit more, I'm a beginner
            and I don't really understand what you are saying. I don't see how I
            am trying to mix the way that I am sending data.
            >
            Thanks!
            >
            You claim you are trying to use data sent as POST and GET at the same time,
            thats a try in mixing, in your example you don't send anything that could be
            fetched with $_GET.


            --- send all as post ---
            <form method="POST" action="">
            <table>

            <tr><td colspan="2" align="center"> Yes <?php
            input_radiochec k('radio','yes_ no', $defaults, 'yes'); ?No <?php
            input_radiochec k('radio','yes_ no', $defaults, 'no'); ?>
            </td></tr>

            <tr><td colspan="2" align="center"> <?php input_submit('s ave','Add'); ?>
            </td></tr>

            </table>
            <input type="hidden" name="isbn" value="<?PHP echo $isbn; ?>" />
            <input type="hidden" name="artist_na me" value="<?PHP echo $artist_name; ?>" />
            <input type="hidden" name="album_tit le" value="<?PHP echo $album_title; ?>" />
            <input type="hidden" name="_submit_c heck" value="1"/>
            </form>
            --- end of example ---

            There you get all the data you needed to send, all sent as post.


            //Aho

            Comment

            • Webwasp

              #7
              Re: Delete Script

              You need to start paying people here buddy. Or just give up on PHP SQL!!!
              <mpar612@gmail. comwrote in message
              news:1155327725 .985414.159590@ 74g2000cwt.goog legroups.com...
              Hi everyone,
              >
              I appreciate all of your help with me and the problems I have been
              having. I'm new to PHP and MySQL and I'm having some problems getting
              this script to work. I can't get this to work and I don't understand
              why. I don't get an error or anything, it almost seems like the page
              refreshes. I went to the phpmyadmin and the row is still in the
              database. The $_GET parts work perfectly in another script and the SQL
              statement works when I insert hard values in it. Any thoughts would be
              greatly appreciated. Thanks in advance.
              >
              <form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>">
              <table>
              >
              <tr><td colspan="2" align="center"> Yes <?php
              input_radiochec k('radio','yes_ no', $defaults, 'yes'); ?No <?php
              input_radiochec k('radio','yes_ no', $defaults, 'no'); ?>
              </td></tr>
              >
              <tr><td colspan="2" align="center"> <?php input_submit('s ave','Add'); ?>
              </td></tr>
              >
              </table>
              <input type="hidden" name="_submit_c heck" value="1"/>
              </form>
              >
              <?php
              >
              function process_form() {
              >
              // Access the global variable $db inside this function
              global $db;
              >
              $isbn = $_GET['isbn'];
              $artist_name = $_GET['artist_name'];
              $album_title = $_GET['album_title'];
              >
              if ($_POST['yes_no'] == 'yes') {
              >
              $delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
              \'$artist_name\ ' AND album_title = \'$album_title\ '";
              // Delete the record
              $db->query($delete_ sql);
              print "The record was deleted";
              } else {
              print "The record was not deleted";
              }
              }
              >
              ?>
              >

              Comment

              • mpar612

                #8
                Re: Delete Script

                Webwasp wrote:
                You need to start paying people here buddy. Or just give up on PHP SQL!!!
                These are forums and responses are voluntary. If you don't want to
                respond, then don't. Responding with comments like yours is not only
                unnecessary, but also a waste of resources and everyone's time.

                Comment

                • Markus Ernst

                  #9
                  Re: Delete Script

                  Webwasp schrieb:
                  You need to start paying people here buddy. Or just give up on PHP SQL!!!
                  Before teaching people how to behave in usenet you might want to learn
                  it yourself:



                  --
                  Markus

                  Comment

                  • Shelly

                    #10
                    Re: Delete Script


                    "Markus Ernst" <derernst@NO#SP #AMgmx.chwrote in message
                    news:44df318e$1 _2@news.cyberci ty.ch...
                    Webwasp schrieb:
                    >You need to start paying people here buddy. Or just give up on PHP SQL!!!
                    >
                    Before teaching people how to behave in usenet you might want to learn it
                    yourself:
                    I agree. The original question was so basic that it was obvious that the
                    writer had done no homework and didn't even know SQL. However, Markus'
                    reply was somewhat over the top. A simple, "You need to learn the basics of
                    SQL first. It is common to all relational databases. Google 'SQL tutorial'
                    online or pick up a book." would have been much more polite.

                    Shelly


                    Comment

                    • Markus Ernst

                      #11
                      Re: Delete Script

                      Shelly schrieb:
                      "Markus Ernst" <derernst@NO#SP #AMgmx.chwrote in message
                      news:44df318e$1 _2@news.cyberci ty.ch...
                      >
                      >>Webwasp schrieb:
                      >>
                      >>>You need to start paying people here buddy. Or just give up on PHP SQL!!!
                      >>
                      >>Before teaching people how to behave in usenet you might want to learn it
                      >>yourself:
                      >
                      >
                      I agree. The original question was so basic that it was obvious that the
                      writer had done no homework and didn't even know SQL. However, Markus'
                      reply was somewhat over the top. A simple, "You need to learn the basics of
                      SQL first. It is common to all relational databases. Google 'SQL tutorial'
                      online or pick up a book." would have been much more polite.
                      I am sure you meant to say that Webwasps reply was somewhat over the
                      top? :-)

                      --
                      Markus

                      Comment

                      • mpar612

                        #12
                        Re: Delete Script


                        Markus Ernst wrote:
                        Shelly schrieb:
                        "Markus Ernst" <derernst@NO#SP #AMgmx.chwrote in message
                        news:44df318e$1 _2@news.cyberci ty.ch...
                        >Webwasp schrieb:
                        >
                        >>You need to start paying people here buddy. Or just give up on PHP SQL!!!
                        >
                        >Before teaching people how to behave in usenet you might want to learn it
                        >yourself:

                        I agree. The original question was so basic that it was obvious that the
                        writer had done no homework and didn't even know SQL. However, Markus'
                        reply was somewhat over the top. A simple, "You need to learn the basics of
                        SQL first. It is common to all relational databases. Google 'SQL tutorial'
                        online or pick up a book." would have been much more polite.
                        >
                        I am sure you meant to say that Webwasps reply was somewhat over the
                        top? :-)
                        >
                        --
                        Markus
                        Okay everyone, let's stop the bad talk and get down to business. This
                        is a forum where people go to for help if they are having problems. I
                        am new to PHP and MySQL and am trying to get a PHP and MySQL site
                        running. I have several books on the subject and I feel I have made
                        great progress in the last 5-6 weeks of working on this with little
                        programming background.

                        If you would like to help me, I would be very appreciative. If you
                        would not like to help, please keep your comments to yourself and not
                        respond. I am looking for any information that would be good. Whether
                        it be an explanation of what is wrong with my code or a link to a good
                        tutorial or even a suggestion to a good book.

                        For those who have tried to help me, thank you very much. I am very
                        appreciative and I say that in each of my responses. For those who
                        like to bash beginners, please keep your comments to yourself.

                        Now let's get back to what these groups are all about: Helping people
                        with PHP and SQL.

                        Thanks

                        Comment

                        • mpar612

                          #13
                          Re: Delete Script


                          J.O. Aho wrote:
                          mpar612 wrote:
                          J.O. Aho wrote:
                          mpar612 wrote:
                          >
                          >Thanks! I should have mentioned that the following is required because
                          >they are being pulled form the url
                          >https://www.domain.com/delete_record...&album_title=:
                          When looking at your example you don't provide this data at all and to make
                          things a lot easier I would include them into the form as hidden input-tags.
                          Things gets a lot easier if you keep on sending data in the same way and not
                          try to mix.
                          >
                          >
                          //Aho
                          Thanks! Could you please elaborate a little bit more, I'm a beginner
                          and I don't really understand what you are saying. I don't see how I
                          am trying to mix the way that I am sending data.

                          Thanks!
                          >
                          You claim you are trying to use data sent as POST and GET at the same time,
                          thats a try in mixing, in your example you don't send anything that could be
                          fetched with $_GET.
                          >
                          >
                          --- send all as post ---
                          <form method="POST" action="">
                          <table>
                          >
                          <tr><td colspan="2" align="center"> Yes <?php
                          input_radiochec k('radio','yes_ no', $defaults, 'yes'); ?No <?php
                          input_radiochec k('radio','yes_ no', $defaults, 'no'); ?>
                          </td></tr>
                          >
                          <tr><td colspan="2" align="center"> <?php input_submit('s ave','Add'); ?>
                          </td></tr>
                          >
                          </table>
                          <input type="hidden" name="isbn" value="<?PHP echo $isbn; ?>" />
                          <input type="hidden" name="artist_na me" value="<?PHP echo $artist_name; ?>" />
                          <input type="hidden" name="album_tit le" value="<?PHP echo $album_title; ?>" />
                          <input type="hidden" name="_submit_c heck" value="1"/>
                          </form>
                          --- end of example ---
                          >
                          There you get all the data you needed to send, all sent as post.
                          >
                          >
                          //Aho
                          Thanks, but I'm afraid that I don't understand why this needs to be
                          done. I have variables, $isbn = $_GET['isbn'], $artist_name =
                          $_GET['artist_name'] and $album_title = $_GET['album_title'] that are
                          pulling information from the url:
                          "www.domain .com/delete_record.p hp?isbn=1234567 689&artist_name =&album_title=. "

                          I want to run the delete query "DELETE FROM lounge WHERE isbn = $isbn
                          AND artist_name=\'$ artist_name\' AND album_title=\'$ album_title\'.

                          The $_GET values work when I do a print $isbn etc... The delete query
                          works in phpmyadmin when I specify hard values for isbn, artist_name
                          and album_title. For example the following query works: DELETE FROM
                          lounge WHERE isbn = 123456789.

                          These things will not work together and I'm not sure why. I believe it
                          is an issue with $isbn = $_GET['isbn'], $artist_name =
                          $_GET['artist_name'] and $album_title = $_GET['album_title'] and
                          inserting the variable names in the SQL query, but I'm not sure how
                          this works. My books don't cover this specific problem in detail.

                          Thank you very much for all of your help. I apologize if I'm asking
                          too many questions.

                          Comment

                          • Markus Ernst

                            #14
                            Re: Delete Script

                            mpar612 schrieb:
                            >
                            Okay everyone, let's stop the bad talk and get down to business. This
                            is a forum where people go to for help if they are having problems. I
                            am new to PHP and MySQL and am trying to get a PHP and MySQL site
                            running. I have several books on the subject and I feel I have made
                            great progress in the last 5-6 weeks of working on this with little
                            programming background.
                            >
                            If you would like to help me, I would be very appreciative. If you
                            would not like to help, please keep your comments to yourself and not
                            respond. I am looking for any information that would be good. Whether
                            it be an explanation of what is wrong with my code or a link to a good
                            tutorial or even a suggestion to a good book.
                            >
                            For those who have tried to help me, thank you very much. I am very
                            appreciative and I say that in each of my responses. For those who
                            like to bash beginners, please keep your comments to yourself.
                            >
                            Now let's get back to what these groups are all about: Helping people
                            with PHP and SQL.
                            >
                            Thanks
                            >
                            1. This is not a support forum, but usenet. People are free to discuss
                            other people's postings in every aspect they consider as worth to be
                            discussed.

                            2. Shelly and me did not blame you, but blamed Webwasp for his/her
                            rudeness when blaming you.

                            3. You get very competent inputs by J.O. Aho in the other branch of this
                            thread. Feel free to ignore other branches like the one here, where the
                            discussion might not be helpful for you.

                            4. 4 days ago you started the thread "MySQL/PHP5 $_GET issue", where you
                            got competent help from J.O. Aho and myself. Instead of trying what J.O.
                            Aho suggested and provided the information necessary for tracking down
                            your problem, you decided to abandon this thread and start a new one.
                            This could be interpreted as a contradiction to your apologies and
                            assertions of appreciacion.

                            As far as I can see you got 2 pieces of advice you did not follow yet:
                            - echo the SQL query to see how it is actually sent to the database
                            - try to not mix GET and POST data
                            What prevents you from just trying it and reporting the results?

                            --
                            Markus

                            Comment

                            • Webwasp

                              #15
                              Re: Delete Script

                              go fuck a piece of code you wrangled out of some!!
                              "mpar612" <mpar612@gmail. comwrote in message
                              news:1155420727 .058240.171280@ p79g2000cwp.goo glegroups.com.. .
                              Webwasp wrote:
                              >You need to start paying people here buddy. Or just give up on PHP SQL!!!
                              >
                              These are forums and responses are voluntary. If you don't want to
                              respond, then don't. Responding with comments like yours is not only
                              unnecessary, but also a waste of resources and everyone's time.
                              >

                              Comment

                              Working...