473,750 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP autofill text box from MySQL

9 New Member
I realize this should probably be a simple solution, but I have only been learning PHP and MySQL for a couple weeks. I am attempting to write an invoicing system that uses a MySQL database to store invoices, product pricing, and customer contact info. I would like to automatically fill in the customer's contact info after typing in the first and last name, and the product pricing info after typing in the product name. From my searches I've found that the onChanged event may be what I'm looking for. However, this only seems to reference JavaScript and AJAX. Is there a way to use this just with PHP? I've done some searching but have very little understanding of JS and AJAX.

Just to make sure my question is clear, I don't want the user to have to click a button to fill in the data, and I don't want to have to reload the page. I just want the customer contact info and pricing info to automatically fill in from the database after tabbing out of the corresponding name text box. I.E. type in first and last name, press Tab, then the phone and address automatically fill in their own text boxes. Or type a product name and press tab, and the pricing info automatically fills in its own text box.

Sorry for being so long-winded. Any suggestions? Is there any code I should post that would help? I can submit the form and update my database w/o any problems, I just have no clue where to begin on this one.

Thanks,
Dybs
Nov 18 '07 #1
16 39476
ak1dnar
1,584 Recognized Expert Top Contributor
http://www.w3schools.com/php/php_ajax_database.asp
In this example can select the FirstName and LastName from a list menu and other details will display using Http Resqusts/Responses. what you have to do get the concept and make it as per your requirement. If you have any doubt please feel free to ask. Good luck!
Nov 18 '07 #2
dybalabj
9 New Member
Ajaxrand,

Thanks for the info. It looks to be almost exactly what I need. However, it only looks to fill the info into a table format. I'd like the info to go into text boxes that the user can edit (say, if the customer moves and needs to change a phone number or something). The only way I know to specify a value in a text box is when it's created by <input type="text" value="somethin g>. Is there anywhere else I can specify the "something" for the text box?

Thanks
Nov 18 '07 #3
The1corrupted
134 New Member
Ajaxrand,

Thanks for the info. It looks to be almost exactly what I need. However, it only looks to fill the info into a table format. I'd like the info to go into text boxes that the user can edit (say, if the customer moves and needs to change a phone number or something). The only way I know to specify a value in a text box is when it's created by <input type="text" value="somethin g>. Is there anywhere else I can specify the "something" for the text box?

Thanks
Here, if you used a post method in a form, this is what it would look like but on the second page, it shows you how to embed php values in a text box.

First Page, callinvoice.htm l

[HTML]
<form action="get_inv oice.php" method="post">
First Name: <input name="first_nam e" type="text" size="20"><br>
Last Name: <input name="last_name " type="text" size="20">
<input type="sumbit" value="Submit">
</form>
[/HTML]

Second Page, get_invoice.php

[PHP]
<?php
$first_name = strtolower($_PO ST['first_name']); //Eliminates case sensitivity
$last_name = strtolower($_PO ST['last_name']);

$table=mysql_qu ery("SELECT * FROM `your_table` WHERE `first_name`='$ first_name' AND `last_name`='$l ast_name'"); //Get your info
$invoicearray=m ysql_fetch_arra y($table); //Stuff it into an array

echo "<form action='updatei nvoice.php' method='post'>
First Name <input type='text' name='fn' value='".$invoi cearray['first_name']."'><br>
Last Name <input type='text' name='ln' value='".$invoi cearray['last_name']."'>
<input type='submit' value='Submit'>
</form>"; //Call each value by their table structure name and embed them into the values of the textboxes. Put single quotes around the embedded information
?>
[/PHP]
Nov 18 '07 #4
dybalabj
9 New Member
OK, It's almost working perfectly now :) I used that tutorial from w3schools and I now have the product and customer info updating correctly, but not quite in the right locations on the page. I think the problem has to do with the placeholder from the <div> tag. I have 2 of these: one for the customer towards the top of the page, another further down for each product line. Here's the code for the customer info:

[PHP]<?php
echo "Customer Info:<br>";
echo "Last:
<input type='text' size=20 name='last'> &nbsp &nbsp &nbsp ";

echo "<script src='selectcust omer.js'></script>";
echo "First:
<input type='text' size=20 name='first' onblur='showCon tact(this.value , last.value)'><b r>";

echo "<div id='cust_info'> ";
echo "Phone 1: &nbsp
<input type='text' size=12 name='phone1'>< br>";

echo "Phone 2: &nbsp
<input type='text' size=12 name='phone2'>< br>";

echo "Address: &nbsp
<input type='text' size=50 name='address'> <br>
</div>";[/PHP]

Here's the code for my product lines:

[PHP]$i=1;
echo "<script src='selectpric e.js'></script>";
while($i<=5){
echo "$i";
echo "<input type='text' size=5 name='quantity$ i'> &nbsp ";
echo "<input type='text' size=90 name='product$i ' onblur='showPri ce(this.value, $i)'>&nbsp ";
echo "<div id='unit'><inpu t type='text' size=6 name='unit$i'></div> &nbsp ";
echo "<input type='text' size=10 name='total$i'> <br>";
$i++;
}[/PHP]


The loop creates a new line with quantity, description, unit price, and total price text boxes. But the <div> tag creates a line break before and after showing the unit price text boxes. Also, For some reason all the updates are occurring in the first product line. So when I update the customer info (which is closer to the top of the form), the phone and address info shows up where the unit price for the first product should be. In my javascript files I do reference the correct div id's, too. Is there something I'm missing?

Thanks,
Dybs
Nov 19 '07 #5
ak1dnar
1,584 Recognized Expert Top Contributor
Thanks for the info. It looks to be almost exactly what I need. However, it only looks to fill the info into a table format. I'd like the info to go into text boxes that the user can edit (say, if the customer moves and needs to change a phone number or something). The only way I know to specify a value in a text box is when it's created by <input type="text" value="somethin g>. Is there anywhere else I can specify the "something" for the text box?
If I am continuing with my earlier post, in that example, Its using "responseTe xt". in other words its printing the server page's out put as it is inside the client side. That's what InnerHTML is doing. So in that case in the client side page they are using a "id" (for <DIV> tags) and that paticular responseText out put coming from the server page will set inside the id using innerHTML. here is the line to which doing the job;
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("txtHint").innerHTML=xmlHttp.responseText
  2.  
  3.  
For your requirement you have do some thing else.


  • Send the name to the server page
  • Get the records for the specific user/customer and print them in the server page. use XML output instead of HTML out put.
  • Parse the XML file,get the xml node values and Set them to the input Text boxes in the client side page. Instead of "innerHTML" you can use "value" attribute for this.
here is another example:
http://www.w3schools.com/php/php_ajax_responsexml.asp
Nov 19 '07 #6
dybalabj
9 New Member
If I am continuing with my earlier post, in that example, Its using "responseTe xt". in other words its printing the server page's out put as it is inside the client side. That's what InnerHTML is doing. So in that case in the client side page they are using a "id" (for <DIV> tags) and that paticular responseText out put coming from the server page will set inside the id using innerHTML. here is the line to which doing the job;
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("txtHint").innerHTML=xmlHttp.responseText
  2.  
  3.  
For your requirement you have do some thing else.


  • Send the name to the server page
  • Get the records for the specific user/customer and print them in the server page. use XML output instead of HTML out put.
  • Parse the XML file,get the xml node values and Set them to the input Text boxes in the client side page. Instead of "innerHTML" you can use "value" attribute for this.
here is another example:
http://www.w3schools.com/php/php_ajax_responsexml.asp
Ajaxrand,
Thanks again for your help. Just to make sure I understand that that example is doing:

1. The <span> tags are placeholders to individual fields, and I can arrange them wherever I need to, they don't necessarily have to be on separate lines, like the <div> tags seem to do.

2. In the PHP page in the example, for the line:
[PHP]echo "<firstname >" . $row['FirstName'] . "</firstname>";[/PHP]

I could replace $row['FirstName'] with
<input type="text" value="$row['FirstName']"> to make sure that my fields are filled in to text boxes in the proper arrangement. Also, the <firstname> tag matches w/ the id in the <span> tag in the HTML form.

Is all that correct? If so, this may be just what I need. Thanks again.
Nov 19 '07 #7
ak1dnar
1,584 Recognized Expert Top Contributor
I'll answer for all your questions, first tell me this. do you want to make this with php-ajax or with pure Php?
Nov 19 '07 #8
ak1dnar
1,584 Recognized Expert Top Contributor
create your Client Side HTML form Tags with a "ID" attribute on it.

[HTML]<input id="txt_name_of _the_id" name="txt_name_ of_the_id" type="text" size="60"/>[/HTML]

Parse the genarated XML file and set the values to the text input boxes, Then The User can Edit them.

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("txt_name_of_the_id").value= 'Set the XML Response Text Value Here instead of this line';
  2.  
Nov 19 '07 #9
dybalabj
9 New Member
I'll answer for all your questions, first tell me this. do you want to make this with php-ajax or with pure Php?
If possible, I'd like to do this with pure PHP, but if it's easier to do w/ php-ajax I'm certainly willing to learn it. As for the document.getEle mentByID() line in your last post, would those go in the stateChanged() function in the javascript file from the examples on w3schools? Or would those go in the php file after my sql query returns my results?

Thanks,
Dybs
Nov 19 '07 #10

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

Similar topics

1
18531
by: shortbackandsides.no | last post by:
I'm having a lot of difficulty trying to persuade the Google toolbar autofill to act consistently, for example ======================= <html><head> <title>autofill test</title> </head><body> <form method="POST" action=""> 1 email <input type="text" name="email"><br> 2 name <input type="text" name="name"> <br>
1
2547
by: Dave | last post by:
Hi All, Just getting started with ASP (NOT .NET) and have a question: I have a basic form and I'm trying to add some functionality to it. I want a user to be able to select a product from a list box. After this product is selected have another text box, ProductID update to reflect the product number. In VB I would use an OnChange type thing. Can anyone point me how to do
2
1858
by: jenese | last post by:
Hi! I've searched the forum and the net for the answer of, probably an easy question for the experienced.... I need to limit the amount of text to 50 first characters when looping out the data from a mysql text-table. How and where do I attack this problem? :confused: Thanks! :cool:
4
15847
by: HTS | last post by:
I have written a membership database application (PHP + mySQL) and need to prevent autofill from filling in fields in a member record edit form. I know I can turn off autoFill in my browsers, I want a away to prevent it within the form itself. Is there any standard way to "tell" a browser not to autofill the fields on a particular form?
0
2056
by: Randy | last post by:
Hi, I have some comboboxes that are created dynamically at run time based on user actions. I found a procedure on a message board to autofill the combobox text from the dataview that the comboboxes are bound to. It works perfectly on the comboboxes that I have created at design time, but the ones that I create runtime behave differently. The problem is that when the user tabs onto the combobox, the box stays blank, which is fine. ...
3
2231
by: Richard | last post by:
Hi all. I have a PHP form for entering data on-line into a mySQL table.. Because of the intended search facility, I require one field in the form to be completed with exact and precise item names and spelling. In testing, I had achieved this with look-up tables. Ideally I would like the selected item from one of five drop-down lists to autopopulate the form text field when selected. Alternatively at least the option of copy and paste....
1
15410
by: Pazeh | last post by:
Hello, a first timer here! stumbled upon one of the threads hear while searching on google & the feedback was awesome so I decided to jump in & ask my Q! I'm a newbie in AJAX, but I know my way pretty well in PHP / MySQL. What is the best/easiest practice that you have used to autocomplete a field & autofill a form? Here is the senario. I have a MySql table with contacts details, I want that when I start filling the name of the contact...
6
38627
by: Shaft11 | last post by:
I have searched and searched and cannot seem to find an answer that fits my needs. Hopefully you can help. I have a database that stores names,addresses, etc. I am trying to get it to where I start typing the last name it will 'suggest' names that are already in the table. ex. If the last name is "Johnson", When I start typing "Jo" it will automatically complete as i type. Any Idea's? Thank you Shaft11
0
8999
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9394
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6803
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4712
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.