how to add form values in two tables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpjawahar
Forum Newbie
Posts: 19
Joined: Thu Jan 12, 2012 6:06 am
Location: Chennai, India

how to add form values in two tables

Post 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
G l a z z
Forum Newbie
Posts: 24
Joined: Sun Feb 12, 2012 10:33 pm

Re: how to add form values in two tables

Post by G l a z z »

Do two mysql queries? lol
phpjawahar
Forum Newbie
Posts: 19
Joined: Thu Jan 12, 2012 6:06 am
Location: Chennai, India

Re: how to add form values in two tables

Post 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?
G l a z z
Forum Newbie
Posts: 24
Joined: Sun Feb 12, 2012 10:33 pm

Re: how to add form values in two tables

Post 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
phpjawahar
Forum Newbie
Posts: 19
Joined: Thu Jan 12, 2012 6:06 am
Location: Chennai, India

Re: how to add form values in two tables

Post 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";
G l a z z
Forum Newbie
Posts: 24
Joined: Sun Feb 12, 2012 10:33 pm

Re: how to add form values in two tables

Post 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 :)
Post Reply