Inserting in two tables from one form

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
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Inserting in two tables from one form

Post by psurrena »

How would I go about inserting information into two tables from one form? This is my current code which is not working.

Code: Select all

<?php
		if(isset($_POST['add'])) {
		
			mysql_connect ("address", "user", "pass") or die ('Error connecting to mysql');
			mysql_select_db (database);
			
			$fname   = $_POST['fname'];
			$lname   = $_POST['lname'];
			$company = $_POST['company'];
			$status	 = $_POST['status'];
			$date	 = $_POST['entry_date'];
			
			$query = "INSERT INTO job (fname,lname,company,status,entry_date) VALUES ('$fname','$lname', '$company','$status',current_date)";
			mysql_query($query) or die ('cannot insert');
			
			
			$jnum	 = $_POST['jobid'];
			$jname	 = $_POST['title'];
			$jdes	 = $_POST['des'];
			$date	 = $_POST['insert_date'];
			
			$queryb = "INSERT INTO jinfo (jobid, title, des, insert_date) VALUES ('$jnum','$jname','$jdes',current_date)";
			mysql_query($queryb) or die ('cannot insert');
			
			header('Location: index.php'); 
		}
	?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

might want to add a mysql_error() output or two in there..
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

I know and will. Should this structure work? Or am I going about it the wrong way? That would be the better question.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's fine.
Post Reply