Page 1 of 1

how to add form values in two tables

Posted: Wed Feb 15, 2012 12:26 am
by phpjawahar
please clear my doubt.
I have two tables,

table 1
personal_info
1. regno
2. empname
3. address
4. mobileno

table 2
office_info
1. regno
2. dateofjoin
3. experience
4. ctc
5. noticeperiod

These two tables have relations with the field 'regno'

Using single form i want to insert the values into these two table. How to do this.

My coding is....

Code: Select all

<?php
error_reporting(0);

if($_REQUEST['submit'])
{
	$regno = $_REQUEST['empregno'];
	$empname = $_REQUEST['empname'];
	$address = $_REQUEST['address'];
	$mobile = $_REQUEST['mobile'];
	$doj = $_REQUEST['doj'];
	$experience = $_REQUEST['pre_exp'];
	$ctc = $_REQUEST['ctc'];
	$notice_period = $_REQUEST['notice_period'];
}
?>


<html>
<head>
<title>Untitled Document</title>
</head>

<body>
<form name="frm" method="post" action="#">
<table>
 <tr>
  <td>Emp Reg No</td>
  <td><input type="text" name="empregno"></td>
 </tr>
 
 <tr>
  <td>Employee Name</td>
  <td><input type="text" name="empname"></td>
 </tr>
 
 <tr>
  <td>Address</td>
  <td><textarea name="address"></textarea></td>
 </tr>
 
 <tr>
  <td>Mobile No</td>
  <td><input type="text" name="mobile"></td>
 </tr>
 
 <tr>
  <td>Date of Joining</td>
  <td><input type="text" name="doj"></td>
 </tr>
 
 <tr>
  <td>Previous Experience</td>
  <td><input type="text" name="pre_exp"></td>
 </tr>
 
 <tr>
  <td>Current CTC</td>
  <td><input type="text" name="ctc"></td>
 </tr>
 
 <tr>
  <td>Notice period</td>
  <td><input type="text" name="notice_period"></td>
 </tr>
 
 <tr>
  <td colspan="2">&nbsp;</td>
 </tr>

 <tr>
  <td colspan="2" align="center"><input type="submit" name="submit" value="Add Employee">&nbsp;&nbsp;<input type="submit" name="cancel" value="Cancel"></td>
 </tr>
</table>
</form>
</body>
</html>

With Regards,
Jawahar

Re: how to add form values in two tables

Posted: Wed Feb 15, 2012 3:21 am
by G l a z z
Do two mysql queries? lol

Re: how to add form values in two tables

Posted: Wed Feb 15, 2012 3:26 am
by phpjawahar
Thanks Glazz,
but some are using .(dot) in the queries.
what is the use of that. Is it to merge the queries or tables?

Re: how to add form values in two tables

Posted: Wed Feb 15, 2012 3:38 am
by G l a z z
Show me the querie you are talking about, so i can take a look =)

But what you want can be done like this:
$insert = mysql_query("INSERT INTO table_name_here SET regno=$regno, empname=$empname");
$insert = mysql_query("INSERT INTO table_name_here2 SET regno=$regno, empname=$dateofjoin");

Something like this

Re: how to add form values in two tables

Posted: Wed Feb 15, 2012 3:57 am
by phpjawahar
Hi,
Here is the query.

$sel = "select a.area_id, a.area_name, a.status, b.city_name from area a, city b where b.city_id = a.city_id order by b.city_name ASC";

Re: how to add form values in two tables

Posted: Wed Feb 15, 2012 4:09 am
by G l a z z
Ahh yes, thats because they are selecting two Tables, look

From
area a,
city b

This means that the table area is going to use a as the name of the table in this query, so you use a.id, a.name, a.etc on the SELECT

Hope you understand what i mean, if not go to google and try searchig for "mysql two tables one query" or something similar :)