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
psurrena
Forum Contributor
Posts: 355 Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY
Post
by psurrena » Fri Apr 07, 2006 12:23 pm
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');
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Apr 07, 2006 12:25 pm
might want to add a
mysql_error() output or two in there..
psurrena
Forum Contributor
Posts: 355 Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY
Post
by psurrena » Fri Apr 07, 2006 12:30 pm
I know and will. Should this structure work? Or am I going about it the wrong way? That would be the better question.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Apr 07, 2006 12:51 pm
it's fine.