Skipjackrick Posted October 17, 2008 Share Posted October 17, 2008 I have a DB table that contains Contestant ID numbers, and their name. When the contestant comes to Check-in I would like to enter the Contestant ID number and have the HTML form automatically populate a text box with the name of the contestant. Is this possible? Or do you know of a tutorial or subject that might cover this? Quote Link to comment Share on other sites More sharing options...
ratcateme Posted October 17, 2008 Share Posted October 17, 2008 look at AJAX it should do that. Scott. Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted October 17, 2008 Author Share Posted October 17, 2008 look at AJAX it should do that. Scott. It seems that I could put a javascript action that says "on mouse over" or "on click" blah blah, query the DB and return the contestent name. Am I wrong? I don't know any AJAX. Quote Link to comment Share on other sites More sharing options...
ratcateme Posted October 17, 2008 Share Posted October 17, 2008 yea if you don't know any but your are ok with PHP checkout the XAJAX project all you would need to do on the javascript side is put a call on your ID input say a onchange. Scott. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 17, 2008 Share Posted October 17, 2008 If you don't care about the page reloading, don't worry about AJAX. <?php if($_GET['id']){ //Lookup info and store it into $c } ?> <html> <body> <form method="GET" action=""> Lookup By Contestant ID: <input type="text name="id" /> <input type="submit" value="Lookup" /><br /> </form> <hr> <form method="POST" action="submit_page.php"> Name: <input type="name" value="<?php echo htmlspecialchars($c['name']); ?>" /> etc </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted October 17, 2008 Author Share Posted October 17, 2008 If you don't care about the page reloading, don't worry about AJAX. I don't want the page to reload, that will use up precious seconds. Basically, the contestant walks up to the table and tells me their ID number. I key in the 3 digit ID into the form. Information such as their name, what division they are entered in, age and location will auto-fill the form. This info would be queried from the DB. This way I can ask the person if their name is "John Smith" after they tell me the contestant ID number. Next, I would enter in the remainder of the necessary information into the form and hit submit. All of this data would be stored in an additional table on the DB. Refreshing the page or having an additional page would take too much time. I'll be entering data for over 600 contestants in less than an hour. Is AJAX my only hope? Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted October 17, 2008 Author Share Posted October 17, 2008 If you don't care about the page reloading, don't worry about AJAX. Wait, by reloading do you mean it will fill the info into the form after I click the submit button and the page will be re-displayed with the form fields populated? Or do you mean, once I enter the ID number and move the mouse, or hit tab to the next field on the form, the page would reload automatically with the info from the DB populated in the appropriate form fields? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 17, 2008 Share Posted October 17, 2008 I mean, they would put in the number, click Lookup, and it would reload the page with the form filled in with the values Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted October 20, 2008 Author Share Posted October 20, 2008 I am having difficulty with the function: $_GET I tried to read some of the tutorials online but they are confusing. I am using the previous code but the form isn't populating once I press lookup. How does the $_GET function know what table to choose in the DB? The table that contains the data is called "user_info" Here is what I've got. <?php //Connect to MySQL $link = mysql_connect("localhost", "user", "pass") or die ("Check your server connection, could not connect to database"); //make sure we're using the right database mysql_select_db ("namelookup"); if($_GET['user_id']){ //Lookup info and store it into $c } ?> <html> <body> <form method="GET" action=""> Lookup By Contestant ID: <input type="text name="id" /> <input type="submit" value="Lookup" /><br /> </form> <hr> <form method="POST" action="submit_page.php"> Name: <input type="name" value="<?php echo htmlspecialchars($c['name']); ?>" /> etc </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 what are the field names inside the user_info table? Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted October 20, 2008 Author Share Posted October 20, 2008 "user_id" and "name" I have another table in my DB that also has a field called "user_id". I am guessing this can't be done..LOL Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 should be able to....list all the tables/fields the needed data is in to populate the form Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted October 20, 2008 Author Share Posted October 20, 2008 should be able to....list all the tables/fields the needed data is in to populate the form When you say list? Is there some syntax for just listing the table needed? Like this? <?php $sql = "SHOW TABLES FROM namelookup"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } ?> I am setting this up for a fishing competition. We will have the names of the participants before the event starts. Once they arrive, we will populate the table "check-in" with the appropriate data. I want the form to populate the name of the contestant by using the "user_id". Each contestant was given a user id number to speed up the check-in process. DB = namelookup DB contains two tables "user_info" and "check_in" "user_info" has two fields user_id name "check_in" has 7 fields entry_id = Primary key (auto increment) user_id name time division tshirt age Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 try this on for size: <?php //Connect to MySQL $link = mysql_connect("localhost", "user", "pass") or die ("Check your server connection, could not connect to database"); //make sure we're using the right database mysql_select_db ("namelookup"); if($_GET['id']){ $error = null; if($result = mysql_query(sprintf("SELECT * FROM user_info WHERE user_id = '%s' LIMIT 1",mysql_real_escape_string($_GET['id'])))){ $c = mysql_fetch_assoc($result); if(!$c){ $error = "User not found"; } }else{ $error = "Query Failed"; } } ?> <html> <body> <form method="GET" action=""> Lookup By Contestant ID: <input type="text" name="id" /> <input type="submit" value="Lookup" /><br /> <?php if($error) echo '<p style="color:red;">Error: '.$error.'</p>'; ?> </form> <hr> <form method="POST" action="submit_page.php"> Name: <input type="name" value="<?php echo htmlspecialchars($c['name']); ?>" /> ...rest of form here... </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted October 20, 2008 Author Share Posted October 20, 2008 AUESOME!!!!!!!! Thanks a million!!!!! Topic solved. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.