Page 1 of 1

Inserting in two tables from one form

Posted: Fri Apr 07, 2006 12:23 pm
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'); 
		}
	?>

Posted: Fri Apr 07, 2006 12:25 pm
by feyd
might want to add a mysql_error() output or two in there..

Posted: Fri Apr 07, 2006 12:30 pm
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.

Posted: Fri Apr 07, 2006 12:51 pm
by feyd
it's fine.