How to automatically insert data to mysql database without submit button in php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • msmjsuarez
    New Member
    • Nov 2009
    • 17

    How to automatically insert data to mysql database without submit button in php?

    Hello,

    I need help...
    How to automatically insert data to mysql database without submit button using php?
    Is there a way on this?


    thanks a lot.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You'll have to be more specific. Can you present an example scenario?

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      to answer the question verbatim (though that probably won’t help), the PHP script does not care, how the data are delivered, as long as they are delivered (somehow). although I guess if it is about user input, a form (with submit button) is definitely the easiest and most straightforward approach.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Hi Msmjsuarez,

        When should your data be inserted into the database?

        It probably shouldn't happen when the user is in the middle of providing updated data...so how can you tell when the data should be inserted?

        An easiest approach is to use a submit button, but you could always use JavaScript to determine if the user is finished editing. Once the user's finished you could use Ajax to submit the information to the server.

        The hard part is going to be determining when the user is finished....whe n it is appropriate to submit the information.

        Also, sometimes users have JavaScript and Ajax disabled so this may cause a problem with your web page. Use the <noscript> tags if you really want to take this approach.

        -Frinny

        Comment

        • msmjsuarez
          New Member
          • Nov 2009
          • 17

          #5
          hi everyone.

          I have one textbox only in a page and the value of the textbox will obtain through the swipe of the barcode.
          The scenario here is that i want to automatically insert the barcode into the mysql database after it is being swiped by the user. More specifically, they will not hit enter anymore after swipe their barcode, it will just automatically inserted to the database.
          How to do this?


          Thanks advance guys.

          Comment

          • dlite922
            Recognized Expert Top Contributor
            • Dec 2007
            • 1586

            #6
            Ok, still you have to know when they're done entering the number. The bar code scanner works just like a keyboard, it just types for you.

            So let's say you type in a bunch of numbers, when should you know it's done typing?

            If the length of the bar code digits are fixed (e.g. 10 digit number), then the following may be a solution:

            Having a javascript look inside the text box every time something is entered (the value is changed), and if it is 10 characters long, validate it, and send it off using AJAX, and then clear the textbox to be ready for the next entry.

            If you have variable length product codes, then maybe a time solution. Every 2 seconds the box is checked for a value and is sent off if it's different than the last sent value.

            You should have a manual mode, where if the bar code is damaged, the operator can hand type the product code into it and press enter.


            Good luck,






            Dan

            Comment

            • msmjsuarez
              New Member
              • Nov 2009
              • 17

              #7
              hi dlite922.

              do you have any codes for this?

              thanks advance.

              Comment

              • captainB
                New Member
                • Aug 2009
                • 23

                #8
                hi msmjsuarez -
                how are you planning on doing this? Is it going to be based on a fixed length of the barcode number, or a timed interval?

                are you going to use javascript?
                It seems like you're going to have to use javascript here.
                Maybe try coding something and post it here?

                B

                Comment

                • msmjsuarez
                  New Member
                  • Nov 2009
                  • 17

                  #9
                  Code:
                  <html> 
                    <head> 
                    <title>HOW TO: Beep when text field full Using Javascript</title> 
                    <meta name="author" content="Shannon Norrell"> 
                    <script language="javascript"> 
                      function DoCheckLength(aTextBox) { 
                        if (aTextBox.maxLength - aTextBox.value.length==0) { 
                          document.theForm.submit(); 
                          //beep.play(); 
                        } 
                      } 
                    </script> 
                  </head> 
                  <body> 
                    <FORM NAME="theForm" action=index.php> 
                      <input type="text" maxlength="12" size="12" 
                  onkeyup="DoCheckLength(this);" ID="firstTextBox" name="firstTextBox"> 
                      <input type="hidden" maxlength="5" size="5" 
                  onkeyup="DoCheckLength(this);" ID="secondTextBox" NAME="secondTextBox"> 
                    </FORM> 
                    <EMBED id="beep" SRC="beep.wav" NAME="beep" AUTOSTART="FALSE" 
                  MASTERSOUND HIDDEN="true"> 
                  </body> 
                  </html>
                  Last edited by Dormilich; Dec 2 '09, 11:04 AM. Reason: Please use [code] tags when posting code

                  Comment

                  • msmjsuarez
                    New Member
                    • Nov 2009
                    • 17

                    #10
                    That's a great solution...just try to develop.

                    Comment

                    • captainB
                      New Member
                      • Aug 2009
                      • 23

                      #11
                      ....would you like me to code the whole thing for you?

                      Comment

                      • msmjsuarez
                        New Member
                        • Nov 2009
                        • 17

                        #12
                        No captainB.

                        Thanks a lot...

                        i'm also a developer and trying to explore such things.

                        :)

                        thanks again.

                        Comment

                        • captainB
                          New Member
                          • Aug 2009
                          • 23

                          #13
                          at any rate, if you know the length of the barcode, it should not be too hard to have the info posted back to the server right away, using ajax, or just the post method of the form...

                          Comment

                          • msmjsuarez
                            New Member
                            • Nov 2009
                            • 17

                            #14
                            I got it already..
                            thanks :)

                            Comment

                            • dlite922
                              Recognized Expert Top Contributor
                              • Dec 2007
                              • 1586

                              #15
                              Originally posted by captainB
                              ....would you like me to code the whole thing for you?
                              I hope you meant this as a joke or trick question. It's again site policy.

                              msmjsuarez has it right. We want the members to explore their own solutions based on our advice.



                              Dan

                              Comment

                              Working...