Re: insert into multiple tables

From: Date: Thu, 05 Apr 2001 02:32:06 +0000
Subject: Re: insert into multiple tables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-47156@lists.php.net to get a copy of this message
On Thu, 5 Apr 2001 02:29, Toni Barskile wrote: > Can someone please help me w/the following code? I'm trying to insert > data collected on a form into two tables into my database. I > know the SQL statements work because I tested them individually, but I > keep getting the error "Couldn't execute query 2". Does > anyone have any suggestions? > > Thanks in Advance > > > Toni > > > <?php > $sql = "INSERT INTO users (fname, lname, compid, status, dept, room, > bldg, phone) VALUES ('$fname', '$lname', '$compid', > > '$status', '$dept', '$room', '$bldg', > '$phone')"; > $sql1 = "INSERT INTO tickets (ticket_num, compid, date_rpt, time_rpt, > request_type, hardware, model, dci, dci_num, software_type, > software_pkg, problem, comments, entered_by) VALUES ('$ticket_num', > '$compid', '$date_rpt', '$time_rpt', '$request_type', > > '$hardware','$model','$dci','$dci_num','$software_type','$software_pkg' >,'$problem','$comments','$entered_by')"; > > /*create connection*/ > $connection = mysql_connect("hostname","user","password") or die > ("Couldn't connect to the server"); > > /*select database*/ > $db = mysql_select_db("db_name", $connection) or die ("Couldn't select > database"); > > /*execute query and get result*/ > $sql_result = mysql_query($sql, $connection) or die ("Couldn't execute > query1"); > $sql_result1 = mysql_query($sql1, $connection) or die ("Couldn't > execute query2"); > > if (!sql_result){ > echo "<p>Couldn't add record!"; > } else{ > > echo " > <p> Record Added!</p> > <table cellspacing=5 cellpadding=5> > /*More code down here...*/ Try using mysql_error() instead of the 'die' so you get an error message back from mysql. My guess is that you are attempting to insert strings into integer fileds. -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#47156) next »