Jump to content

Auto filling the Text boxes from Database


Dinzy

Recommended Posts

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]

Link to comment
Share on other sites

Well your existing code shown no offence makes no sense, as on page load its going to get an SQL error, as there is no connection to work with. However if its defined somewhere else and you havent shown that, ok.. but with this code from the looks of it your just posting empty data to a database as soon as the page loads..

 

If you want to auto populate fields in the form then you need to query an existing database for what you want those field values to be..

 

then in the <input> tags you put a line value="$myDBValue" (of course you need to edit it to your needs.. but generally speaking thats all there is to auto population

 

the code given here really doesnt make sense to your described need and desire though, and youve provided little background otherwise on how your orgainizing your data for use to do auto populations and otherwise so its not likely anyone can really help you much unless more is known.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.