PHP - Moved: Auto Fill Fields From The Database
This topic has been moved to Ajax Help.
http://www.phpfreaks.com/forums/index.php?topic=352528.0 Similar Tutorialshi, i looking for a way to use a auto fill for a inputbox text but all that i found is using a mysql bd. there is any solution using a txt file? stored in server. thanks a lot for your help Hi All Not sure if this is possible, but I spend loads of time filling in the same form on a 3rd party website when people send me their details to check. Is there any way I am able to build a php script to read and check their details (can do this bit) and then submit them to a form on another website (can't do this bit)? The form is a hotel booking form and is spread over 4 pages. I am creating a simple web application that allows the user to update information in a database. I have a selector that allows the user to select what record they want to update and then a form field to insert the data to be updated. I want the form to to be passed the data from the selected entry "when selected" to auto-complete the default values of the text fields so the user can see the information right in the text fields. This is the form Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Tom's Culture Database</title> <meta name="GENERATOR" content="Quanta Plus"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <style> body { } h3 { color: #585858; } h4 { color : #c00000; } th { background : #000000; border : #ffffff solid 1px; color : #ff0000; text-align : left; } .form_wrapper { background : #000000; padding : 10px; border : solid 2px; } #form_inner { padding : 0 0 0 5px; display : inline-block; } td { border : #000000 solid 1px; } </style> <body> <?php //CONNECT INCLUDE require("connect.php"); //SELECT DATABASE $sql_user_info = mysql_query("SELECT * FROM collections ORDER BY id ASC"); //BEGIN FORM echo "<h3>Select an entry to update or delete!</h3> <form action='mysql_update_action.php' method='POST'><select name='name_select'>"; while ($row = mysql_fetch_assoc($sql_user_info)) { $id = $row['id']; $genus = $row['genus']; $species = $row['species']; $strain_name= $row['strain_name']; echo " <option value = '$id'>$id : $genus $species $strain_name</option> "; } echo "</select> <br><br><br> <DIV class='form_wrapper'> <DIV id='form_inner' align=\"left\"><h4>Genus Name:</h4><INPUT type=\"text\" name=\"to_change_genus_name\"></DIV> <DIV id='form_inner' align=\"left\"><h4>Species Name:</h4><INPUT type=\"text\" name=\"to_change_species_name\"></DIV> <DIV id='form_inner' align=\"left\"><h4>Strain Name:</h4><INPUT type=\"text\"name=\"to_change_strain_name\"></DIV> <DIV id='form_inner' align=\"left\"><h4>P-Value:</h4><INPUT type=\"text\" name=\"to_change_p_value\"></DIV> <DIV id='form_inner' align=\"left\"><h4>Origin:</h4><INPUT type=\"text\" name=\"to_change_origin\"></DIV> <DIV id='form_inner' align=\"left\"><h4>Get From:</h4><INPUT type=\"text\" name=\"to_change_get_from\"></DIV> <DIV id='form_inner' align=\"left\"><h4>Qty:</h4><INPUT type=\"text\" name=\"to_change_qty\"></DIV> <DIV id='form_inner' align=\"left\"><h4>Created:</h4><INPUT type=\"text\" name=\"to_change_date_created\" value=\"M/D/Y\"></DIV><br> <DIV id='form_inner' align=\"left\"><h4>Working Collection:</h4><INPUT type=\"checkbox\" name=\"to_change_work_collection\"></DIV> <DIV id='form_inner' align=\"left\"><h4>DNA Check:</h4><INPUT type=\"checkbox\" name=\"to_change_dna_check\"> </DIV> <br><br> <INPUT type='submit' name='change' value='Update'> <INPUT type='submit' name='name_delete' value='Delete'> </form></DIV>"; //END FORM ?> <?php //SELECT DATABASE $sql_user_info = mysql_query("SELECT * FROM collections ORDER BY id"); while ($row = mysql_fetch_assoc($sql_user_info)) { $id = $row['id']; $genus = $row['genus']; $species = $row['species']; $strain_name = $row['strain_name']; $p_value = $row['p_value']; $origin = $row['origin']; $get_from = $row['get_from']; $qty = $row['qty']; $work_collection = $row['work_collection']; $dna_check = $row['dna_check']; $date_created = $row['date_created']; $last_modified = $row['last_modified']; if ($work_collection == "0"){ $work_collection = "no"; } else { $work_collection = "yes"; } // Define $color=1 echo "<br>"; echo "<table width='400' border='1' align='left' cellpadding='2' cellspacing='0'>"; echo "<tr><th>ID</th><th>Genus</th><th>Species</th><th>Strain Name</th><th>P-Value</th></tr>"; $color= 1; // If $color==1 table row color = #FFC600 if($color==1){ echo "<tr bgcolor='#808080'><td>".$id."</td><td>".$genus."</td><td>".$species."</td></tr>"; // Set $color==2, for switching to other colors $color=2; } // When $color not equal 1, use this table row color else { echo "<tr bgcolor='#ffffff'><td>".$id."</td><td>".$genus."</td><td>".$species."</td></tr>"; // Set $color back to 1 $color='1'; } echo "</table>"; } ?> </body> </html> This is the update actions Code: [Select] <?php //CONNECT INCLUDE require("connect.php"); //GRAB DATA $name_select = $_POST['name_select']; $name_delete = $_POST['name_delete']; $to_change_genus_name = $_POST['to_change_genus_name']; $to_change_species_name = $_POST['to_change_species_name']; $to_change_strain_name = $_POST['to_change_strain_name']; $to_change_p_value = $_POST['to_change_p_value']; $to_change_origin = $_POST['to_change_origin']; $to_change_get_from = $_POST['to_change_get_from']; $to_change_qty = $_POST['to_change_qty']; $to_change_work_collection = $_POST['to_change_work_collection']; $to_change_dna_check = $_POST['to_change_dna_check']; $to_change_date_created = $_POST['to_change_date_created']; $date = strtotime("now"); $current_date = date("m/d/y", $date); if ($name_select&&$to_change_genus_name&&$_POST['change']) { $change = mysql_query("UPDATE collections SET genus='$to_change_genus_name', species='$to_change_species_name' WHERE id='$name_select'"); echo "<br><h2>Data updated</h2><br>"; header( 'Location: http://localhost/sam/Mycelium.eu/mysql_update.php' ) ; } elseif ($_POST['name_delete']) { $delete = mysql_query("DELETE FROM collections WHERE id='$name_select'"); echo "<br><h2>Data deleted</h2><br>"; header( 'Location: http://localhost/sam/Mycelium.eu/mysql_update.php' ) ; } else echo "Please enter some Information"; header( 'Location: http://localhost/sam/Mycelium.eu/mysql_update.php' ) ; ?> Can someone help me with this.. I cannot figure out why it will not log in.. The actual url and user/pass are valid so feel free to test the live site. <?php // INIT CURL $ch = curl_init(); // SET URL FOR THE POST FORM LOGIN curl_setopt($ch, CURLOPT_URL, 'http://www.handy-hanky.com/shirley/homesell_cron.htm'); // ENABLE HTTP POST curl_setopt ($ch, CURLOPT_POST, 1); // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD curl_setopt ($ch, CURLOPT_POSTFIELDS, 'user=tom&pass=test&login_theme=cpanel'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); // EXECUTE 1st REQUEST (FORM LOGIN) $store = curl_exec ($ch); echo "STORE = $store<br>"; // CLOSE CURL curl_close ($ch); ?> I have database that is a list of categories that I would like to insert into a switch statement. This is the only way that I know how to do it right off hand and of course it doesn't work. I've looked on the internet and found examples but they are slightly over my head as ways to do it. Depending on $group which comes from the url a title an h1 would be assigned. Code: [Select] $q = "SELECT * FROM categories"; $r = @mysqli_query ($dbc, $q); switch ($group) { if ($r) { //If $r ran OK while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){ case '$row['id_cat']': $h1 = '.$row['group']'; break; } } } Thanks S Hello, I want to create a custom user profile, by allowing admin to add them from admin panel then users can fill their values. How can I create such system ? Thanks. Here goes.
I am trying to retrieve info. from mySql database and update 3 textfields.
I also have 4 selects on the form that need populating during the running of the program. My problem is using console I can see the info - Customer name - but it does not appear in the text field. The onchange request in the DIV container seems to be where it fails. Here are the files I am using:
1. add_an_order.php
<html> <head> <title>Add an Order</title> <link href = "css/style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="include/jquery-1.11.1.min.js"></script> </head> <body> <div id="header"><img src="images/logo.png" /></div> <div id="nav"> <div id="nav_wrapper"> <ul> <li><a href="index.php">Orders</a></li><li> <a href="customers.php">Customers</a></li><li> <a href="contacts.php">Contacts</a></li><li> <a href="batteries.php">Batteries</a></li><li> <a href="#">Queries</a> </li> </ul> </div> </div> <div id="main"> <?php echo '<h3 id="menOpt">Add an Order</h3><hr>'; // Check for a form submission. /* if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); $required_fields = array('customer_name', 'customer_address', 'city', 'telephone'); foreach ($required_fields as $fieldname) { if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) { $errors[] = strtoupper($fieldname); } } if (empty($errors)) { include ('include/dbconnect.php'); $name = mysqli_real_escape_string($con, trim(strip_tags($_POST['customer_name']))); $contact = mysqli_real_escape_string($con, trim(strip_tags($_POST['contact']))); $address = mysqli_real_escape_string($con, trim(strip_tags($_POST['customer_address']))); $city = mysqli_real_escape_string($con, trim(strip_tags($_POST['city']))); $telephone = mysqli_real_escape_string($con, trim(strip_tags($_POST['telephone']))); $telephone = preg_replace('/[^0-9]/', '', $telephone); if (isset($_POST['deepc'])) { $deepc = 1; } else { $deepc = 0; } if (isset($_POST['problemc'])) { $problemc = 1; } else { $problemc = 0; } $problem = mysqli_real_escape_string($con, trim(strip_tags($_POST['problem']))); if (isset($_POST['blacklist'])) { $blacklist = 1; } else { $blacklist = 0; } if (isset($_POST['pickup'])) { $pickup = 1; } else { $pickup = 0; } $query = "INSERT INTO customers ( customer_name, contact, customer_address, city, telephone, deep_cycle, problem_customer, problem, blacklist, pickup) VALUES ('$name', '$contact', '$address', '$city', '$telephone', $deepc, $problemc, '$problem', $blacklist, $pickup)"; $r = mysqli_query($con, $query); if (mysqli_affected_rows($con) == 1) { echo '<p class="success">Customer has been successfully added.</p>'; } else { $message = "Could not add customer."; $message .= "<br />" . mysqli_error($con); } mysqli_close($con); } else { // We have errors. $message = count($errors) . " error(s) on the form."; } } // End: if ($_SERVER['REQUEST_METHOD'] == 'POST'). */ // Leave PHP and display the form. ?> <?php if (!empty($message)) { echo '<p class="error">' . $message . '</p>'; } ?> <?php // Output list of fields that have errors. if (!empty($errors)) { echo '<p class="error">'; foreach ($errors as $error) { echo $error . '<br />'; } echo '</p>'; } ?> <div class="container"> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <label>Business: <span class="important"> *</span><select name="customer_name" id="customer_name" onchange="request_fill(this.value)" value="<?php if (isset($_POST['customer_name'])) echo $_POST['customer_name']; ?>" ></select></label> <label>Address: <input type="text" name="address" id="add_a" value="<?php if (isset($_POST['customer_address'])) echo $_POST['customer_address']; ?>" /></label> <label>City: <input type="text" name="city" id="city" value="<?php if (isset($_POST['city'])) echo $_POST['city']; ?>" /></label> <label>Phone: <input type="text" name="telephone" value="<?php if (isset($_POST['telephone'])) echo $_POST['telephone']; ?>" /></label> <label>Manufacturer: <span class="important"> *</span><select name="manufacturer" id="manufacturer" onchange="request_mod(this.value)" value="<?php if (isset($_POST['manufacturer'])) echo $_POST['manufacturer']; ?>" ></select></label> <label>Model: <span class="important"> *</span><select name="model" id="model" onchange="form_yr(this.value)" value="<?php if (isset($_POST['model'])) echo $_POST['model']; ?>" ></select></label> <label>Year: <span class="important"> *</span><select name="battery" id="bat_disp" value="<?php if (isset($_POST['battery'])) echo $_POST['year'] ?>" ></select></label> <label>Quantity: <span class="important"> *</span><input type="text" name="quantity" id="quantity" value="<?php if (isset($_POST['quantity'])) echo $_POST['quantity']; ?>" /></label> <label>Warranty ? <input type="checkbox" name="warranty" <?php if ($_POST['warranty']) echo " checked"; ?> /></label> <label>Exchange ? <input type="checkbox" name="exchange" <?php if ($_POST['exchange']) echo " checked"; ?> /></label> <input type="submit" name="submit" value="Add Order" /> or <a href="index.php">Cancel</a> </fieldset> </form> </div> <script type="text/javascript" src="include/functions.js"></script> <script> $(document).ready(function() { $('.container').hide(); $('.container').fadeIn(1000); request_cust(); request_man(); }); </script> <?php include ('include/footer.php'); 2. request_fill function request_fill() { var cust2 = 'customer'; var ad = document.getElementById("add_a"); var hr = new XMLHttpRequest(); hr.open("POST", "battery_parser.php", true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if(hr.readyState == 4 && hr.status == 200) { var dataArray = hr.responseText; ad.innerHTML = dataArray[1]; } } hr.send("&cust2="+cust2); } 3. battery_parser.php <?php include_once("include/dbconnect.php"); if (isset($_POST['cust2'])) { $cust2 = $_POST['cust2']; $sql = "SELECT customer_address FROM customers WHERE customer_id = 2"; $query = mysqli_query($con, $sql); $dataString = ''; while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ $add = $row["customer_address"]; $dataString = $add; } mysqli_close($con); echo $dataString; exit(); } else { exit(); } ?> Hi can anybody help I need to export and download tables from a database into a excel sheet. I have this code and it works what I need is to export specific fields and not just the whole table can anyone help modifying the code to export certain fields within the table please? Here is the code... Code: [Select] <?php $host = 'localhost'; $user = 'user'; $pass = 'password'; $db = 'qdbname'; $table = 'tablename'; $file = 'export'; $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error()); mysql_select_db($db) or die("Can not connect."); $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field']."; "; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j]."; "; } $csv_output .= "\n"; } $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?> I am quite new to PHP and MySQL. I am trying to figure out what datatypes to use for different fields in a Database. For ID (Identification) I use INT, for name I use VARCHAR and for people to write text messages, I use LONGTEXT. For date and time I use DATETIME.
What I am unsure about, however, is what type to use for an email adress and for an IP address? I have been watching videos at Youtube about the Datatype for IP addresses, but they don't seem always to agree. I hope someone can put me in the right direction on those two.
Regards,
Erik
Hi all, I'm brand new to php / mysql and I'm trying to modify this script which currently runs a search on two fields "product_number" and "product_name". I also want the search to consider a third field "product_type". When I remove either product_name or product number from the following part of the code, it removes that field from being considered in the search: Code: [Select] $search_map = array($orderby, 'product_number','product_name',); So shouldn't I be able to just add the third field's name to this array and have it be considered too? I'm a complete beginner so I'm hoping this is a simple fix and I just dont get it. Here's the rest of what I think is the relevant code: Code: [Select] function load_all_products() { global $AppUI; global $sorted_item_list; global $additional_pfilter; load_type_list(); $orderby = 'product_id'; $search_map = array($orderby, 'product_number','product_name',); $where = $AppUI->getState( 'QuoteIdxWhere' ) ? $AppUI->getState( 'QuoteIdxWhere' ) : '*'; $not =" "; $op = " OR"; $check = substr(trim($where),0,4); if(stristr($check,"NOT")){ $op ="AND"; $not = " NOT "; $where = substr(trim($where),4); $where = trim($where); } // assemble the sql statement $q = new DBQuery; $q->addTable('products'); $q->addJoin('companies', 'com', 'products.product_company_id = com.company_id'); $q->addJoin('users', 'u', 'products.product_owner = u.user_id'); $q->addQuery('products.*, com.company_name, u.user_username'); $where_filter = " "; foreach($search_map as $search_name) $where_filter .=" $op $search_name $not REGEXP '$where'"; $where_filter = substr($where_filter, 5); // echo $where_filter; if($where != "*") $q->addWhere("($where_filter)"); $q->addOrder('product_id'); $sql = $q->prepare(); $q->clear(); $sql_list = db_exec( $sql ); if ($sql_list) $rn = db_num_rows( $sql_list ); else { echo db_error(); $rn = 0; } $product_list = array(); foreach ($sql_list as $item) { $product_list[ $item[ 'product_id' ] ] = $item; } // sort the list global $sort_state; if ( !isset( $sort_state ) ) $sort_state = getProductSortState(); if ( isset( $sort_state[ 'sort_item1' ] ) ) { if ( isset( $sort_state[ 'sort_item2' ] ) ) { $sorted_item_list = array_csort2( $product_list, $sort_state['sort_item1'], intval( $sort_state['sort_order1'] ) , $sort_state[ 'sort_item2' ], intval( $sort_state['sort_order2'] ) ); } else { $sorted_item_list = array_csort2( $product_list, $sort_state['sort_item1'], intval($sort_state['sort_order1']) ); } } else $sorted_item_list = array_csort2( $product_list, 'product_id' ); } Thanks! Hiya I was wondering how one would get make dynamic url variable value pairs from a databases fields. I have a database that I want to use to store variable value pairs that will be used on my pages for dynamic content. It will check one thing for certain besides if the variable value pair match. The table looks like this rpg loc_type loc_type template I want it to check if the rpg is in an array and then check if the url variable and value pair match on from the database. I dont know much about auto code that would generate this on its own and I'm not sure if you can say $_GET[$location]; I dont want to hard code it so it only works with what i code I want the urls variable value pair to be based on the database info which determines which template to show based on those values. I wrote a piece of code that lists images that don't have a match in the database: Code: [Select] $dir_path = '../images/productImages'; $images = scandir($dir_path); $query = "SELECT image FROM Database_table ORDER BY name DESC"; $results = mysql_query($query); $output = "<h1>Missing Images</h1>"; $output .= "<div class=\"missingImages\">"; $output .= "<p>The following data was found in the Database_table.images field but not in /images/productImages:</p>"; $output .= "<div class=\"missingImg\">"; $output .= "<p class=\"fieldName\">Database_table.images:</p>"; while ($fetch = mysql_fetch_array($results)) { $clean_fetch = str_replace("productImages/", "", $fetch); $diff = array_diff($clean_fetch, $images); foreach (array_unique($diff) as $key => $value) { $output .= $value . "<br />"; } } $output .= "</div>"; $output .= "</div>"; echo $output; Works. Now I would like to check whether there are any files in the folder that are not in the database table. I thought it would be as easy as swapping the array_diff parameters around but it's not. When i swap the parameters like so - array_diff($images, $clean_fetch) it gives me a list of ALMOST all the images in the image folder, which i don't understand. Why does it not give me only the images that are present in the folder but not in the database? Hi. I have the following code to delete a row when the date has passed. Code: [Select] $today = date("dmY"); $vLongDate = date("dmY", strtotime($thisDate)); if ($today > $vLongDate) { mysql_query("DELETE FROM events WHERE id < '$id'"); } $today is current date, while $vLongDate is the date that is on my database. Am i doing the if statement correctly?? Hi friends, a quick print_r() shows the following array while connecting to my database. How to get them as individual items and display on the website ? Array ( [0] => Array ( [id] => 52 [document_name] => xyz [document_ext] => gif [download_file_name] => ktm_impact.gif [upload_dt] => 2010-08-11 ) ) hi every body.
i want a loop that takes and shows more than one record from database.
and then i want to show these to user by ajax.
indeed i made an html page that when user arrives at end it must do this.
first i made loop that took one record from database and it worked fine.
but for taking several records it went wrong.
this is my html file that has interact by user
webgoo-ajax.html 4.36KB
2 downloads
and this is my php file that interacts by database
ajax-get.php 1012bytes
3 downloads
when user arrives at end of page naturally ajax must be run and show several records to user.but it does'nt.
first it stays idle for 3 minutes and then loads my first record extremely.
and a point: if these pages does'nt work on IE it will work on Firefox because it did'nt worked in IE for me too.
i just want a for loop that work correctly for my need.
thank you for everything
I have a relational table call sales with prodcut_id and custmer_id tables. I also have a product and customer tables. products table with product_id as an auto increment and customer with custumer_id I want to join through the sales tables all t he fields of row 1 from tables customer and products and pull it at once. This is a member login script and I want to display the products by members. So far I have this query to display the products once the member is login in. $userid is the id of the customer coming from the $userid= $_SESSION['customer_id']; $mysqlSales="SELECT products.* FROM products JOIN sales ON (products.product_id = procuct_id ) WHERE sales.customer_id = '$userid'"; so far that statement is not working where should I have some type of incoherance with the english statement above expressing what I want the query to do. Hi, I'm trying to get a php webform to log onto the database automatically before it loads on the website page. In other words I don't want the customer having log onto the database or be a guest. I think I need the code below to do that. Question is, can I just add this code into the php file that is the webform or add the <?php ?> to it and have it above the webform php code. Also do I need to alter any other dbconnect php pages as well? Also do I need to edit the htaccess file also. function verify_code() { $connection = mysql_connect ("localhost", "fred", "kool3401") or die ('Error: ' . mysql_error()); $db = mysql_select_db ("october"); { echo "Authenticated"; } Many Thanks I'm using PHP and MySQL. I have an application where I'd like to keep certain database (character) fields encrypted when added to the database and stored, but when I need to display them at the appropriate time, I can call a function and quickly decrypt them for display. Does anyone know of a simple way to do this? Thanks! I can not get the values from the javascript add row to go dynamically as a row into MySql only the form values show up as the form below as one row. I made it as an array, but no such luck, I have tried this code around a multitude of ways. I don't know what I am doing wrong, kindly write out the correct way.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...ransitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Dynamic Fields js/php to MySql need to submit dynamically to the database</title> <?php require ('database.php'); ?> <script type="text/javascript"> var counter = 1; var collector = ""; function addfields(indx) { var tbl = document.getElementById('table_id'); var newtr = document.createElement('tr'); counter = counter + indx; newtr.setAttribute('id','tr'+counter); newtr.innerHTML = '<td><input type="checkbox" name="checkb'+counter+'" id="checkb'+counter+'" value="'+counter+'" onclick="checkme('+counter+')"></td><td><input type="text" name="text1[]"></td><td><textarea name="textarea1[]"></textarea></td>'; tbl.appendChild(newtr); } function checkme(dx) { collector += dx+","; } function deletetherow(indx) { var col = collector.split(","); for (var i = 0; i < col.length; i++) { var remvelem = document.getElementById('tr'+col[i]); var chckbx = document.getElementById("checkb"+col[i]); if(remvelem && chckbx.checked) { var tbl = document.getElementById('table_id'); tbl.removeChild(remvelem); } } } </script> </head> <body> <form enctype="multipart/form-data" id="1" style="background-color:#ffffff;" action="<?php echo $_SERVER['PHP_SELF']; ?>"></form> <table id="table_id" > <tr id="tr1" class="trmain"> <td> </td> <td> <input type="text" name="text1[]"> </td> <td> <textarea name="textarea1[]"></textarea> </td> </tr> </table> <input type="button" value="Add" onClick="addfields(1);" /> <input type="button" value="Delete" onClick="deletetherow()" /> <input type="submit" value="Send" id="submit" name="submit"/> <?php if(isset($_POST['submit'])) { for ($i=0; $i < count($_POST['text1']); $i++ ) { $ced = stripslashes($_POST['text1'][$i]); $erg = stripslashes($_POST['textarea1'][$i]); } $bnt = mysql_query("INSERT INTO tablename (first, second) VALUES ('$ced', '$erg')")or die('Error: '. mysql_error() ); $result = mysql_query($bnt); } ?> </body> </html> Hello all, I have three text fields ( hosteladmissionnumber,branch & Semester) and three text boxes in a form. When i provide the hostel admission number , the corresponding branch semester must be acquired from the registrationtable in DB and fill it in text boxes. How can i do it? any help would be appreciated. Thanks. I have pasted the code below. [syntax=php] <?php session_start(); $hostad=$_POST['hosteladmissionno']; $sem=$_POST['student_name']; $sem=$_POST['semester']; $con=mysql_connect('localhost','root',''); if(!$con) { die('Unable to connect'.mysql_error()); } mysql_select_db('hostel',$con); //i have to insert the hosteladmission in payment too..but no need to insert semester and branch $r1="INSERT INTO payment(hosteladmissionno) values ('$hostad')"; mysql_close($con); ?> /HTML PART <form action='payment.php' method='POST' name='form1'> <center> <table> <tr><td><b>Admission No:</b></td><td><input type='text' name='hosteladmissionno'></td></tr> <tr><td><b>Student Name:</b></td><td><input type='text' name='student_name'></td></tr> <tr><td><b>Semester:</b></td><td><input type='text' name='semester'></td></tr> [/syntax] |