By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,304 Members | 3,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,304 IT Pros & Developers. It's quick & easy.

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

P: 17
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.
Dec 1 '09 #1
Share this Question
Share on Google+
17 Replies


Markus
Expert 5K+
P: 6,050
You'll have to be more specific. Can you present an example scenario?
Dec 1 '09 #2

Dormilich
Expert Mod 5K+
P: 8,639
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.
Dec 1 '09 #3

Frinavale
Expert Mod 5K+
P: 9,731
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....when 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
Dec 1 '09 #4

P: 17
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.
Dec 2 '09 #5

dlite922
Expert 100+
P: 1,584
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
Dec 2 '09 #6

P: 17
hi dlite922.

do you have any codes for this?

thanks advance.
Dec 2 '09 #7

P: 23
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
Dec 2 '09 #8

P: 17
Expand|Select|Wrap|Line Numbers
  1. <html> 
  2.   <head> 
  3.   <title>HOW TO: Beep when text field full Using Javascript</title> 
  4.   <meta name="author" content="Shannon Norrell"> 
  5.   <script language="javascript"> 
  6.     function DoCheckLength(aTextBox) { 
  7.       if (aTextBox.maxLength - aTextBox.value.length==0) { 
  8.         document.theForm.submit(); 
  9.         //beep.play(); 
  10.       } 
  11.     } 
  12.   </script> 
  13. </head> 
  14. <body> 
  15.   <FORM NAME="theForm" action=index.php> 
  16.     <input type="text" maxlength="12" size="12" 
  17. onkeyup="DoCheckLength(this);" ID="firstTextBox" name="firstTextBox"> 
  18.     <input type="hidden" maxlength="5" size="5" 
  19. onkeyup="DoCheckLength(this);" ID="secondTextBox" NAME="secondTextBox"> 
  20.   </FORM> 
  21.   <EMBED id="beep" SRC="beep.wav" NAME="beep" AUTOSTART="FALSE" 
  22. MASTERSOUND HIDDEN="true"> 
  23. </body> 
  24. </html>
Dec 2 '09 #9

P: 17
That's a great solution...just try to develop.
Dec 2 '09 #10

P: 23
....would you like me to code the whole thing for you?
Dec 2 '09 #11

P: 17
No captainB.

Thanks a lot...

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

:)

thanks again.
Dec 2 '09 #12

P: 23
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...
Dec 2 '09 #13

P: 17
I got it already..
thanks :)
Dec 2 '09 #14

dlite922
Expert 100+
P: 1,584
@captainB
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
Dec 2 '09 #15

P: 23
yea, it was a joke....but not a very good one I guess :)
Dec 2 '09 #16

P: 17
Hello.

Is it possible to insert data to two tables at one time using one form only?

I'm using php and mysql.

Thanks advance.
Dec 3 '09 #17

P: 23
In your server-side code you can run two separate SQL INSERT statements when the form is posted, one for each table.
You can also execute a stored procedure and pass it your form values, and have it insert the values to two tables or more.

If you need more help, maybe you can post some more information, like -
what are the FORM values you are inserting?
What is the table structure of these 2 tables?

Good luck!
Dec 3 '09 #18

Post your reply

Sign in to post your reply or Sign up for a free account.