One Form Two Tables -- HELP

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
kim5975
Forum Newbie
Posts: 2
Joined: Fri May 29, 2009 8:43 pm

One Form Two Tables -- HELP

Post by kim5975 »

:? Can someone please help me figure out what I have wrong here....when I hit submit, nothing goes into my tables....please review the attached. Thank you very much! Kim :banghead:
allineed.jpg
allineed.jpg (88.17 KiB) Viewed 285 times
What I have:

Code: Select all

<?php
//session_start();
 
// check logged in or not
//if (!isset($_SESSION['db_is_logged_in'])
  // || $_SESSION['db_is_logged_in'] !== true) {
 
   // no...move to login page
//   header('Location: index.php');
 //  exit;
//}
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Companies Represented</title>
</head>
<body bgcolor="#EFEFEF">
<p align="left" style="margin-top:0px; margin-bottom:0px">&nbsp;</p>
 
 
<?php
include("config.php");
include("opendb.php");
if(isset($_POST['submit']))
 {//begin of $submit).
      $exid = $_POST['exid'];
      $name = $_POST['exhibit.name'];
      $address = $_POST['address'];
      $fax = $_POST['fax'];
      $email = $_POST['email'];
      $web = $_POST['web'];
      $contact1 = $_POST ['contact1'];
      $contact2 = $_POST ['contact2'];
      $contact3 = $_POST ['contact3'];
      $contact4 = $_POST ['contact4'];
      $desc = $_POST ['desc'];
      $name2 = $_POST[$name];
      $rep = $_POST['rep'];
      $product = $_POST['product'];
 
       
$result = "INSERT INTO exhibit (exid, name, address, phone, fax, email, web, contact1, contact2, contact3, contact4, desc) VALUES ('$exid', '$name', '$address', '$phone', '$fax', '$email', '$web', '$contact1', '$contact2', '$contact3', '$contact4', '$desc')";
print $result;
mysql_query($result,$connect);     
 
 
 
//while($myrow = mysql_fetch_assoc($result))
    //         {
      //          $name = $_POST['name'];
                 
foreach ($rep as $key => $repv) {
$SQL = "INSERT INTO companies (coid, name, rep, product) values ('$coid', '$name2', '$repv', '$product[$key]')";
print $SQL;
mysql_query($SQL, $connect);        
      }                  
//foreach($_REQUEST['rep'] as $rep) && foreach($_REQUEST['product'] as $product);               
//mysql_query("INSERT INTO companies (coid, name, rep, product) values ('$coid', '$name2', '$rep', '$product')", $connect);   
       
   
echo "<br><b>Thank you! Your information has been received successfully!";
      }    
 
  // has the form been submitted?
else
  {//begin of else
?> 
<br />
 
 
 
<form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER[PHP_SELF] ?>">
 
<table width="700" border="1" align="left" cellpadding="2" cellspacing="2">
 
<tr>
 
<td width="150">Company Name</td>
 
<td><input name="name" type="text" id="name1" size="50"></td>
 
</tr>
 
<tr>
 
<td width="150">Address</td>
 
<td><input name="address" type="text" id="address" size="50"></td>
 
</tr>
 
<tr>
 
<td width="150">Phone</td>
 
<td><input name="phone" type="text" id="phone" size="50"></td>
 
</tr>
 
<tr>
 
<td width="150">Fax</td>
 
<td><input name="fax" type="text" id="fax" size="50"></td>
 
</tr>
 
<tr>
 
<td width="150">Email</td>
 
<td><input name="email" type="text" id="email" size="50"></td>
 
</tr>
 
<tr>
 
<td width="150">Website</td>
 
<td><input name="web" type="text" id="web" size="50"></td>
 
</tr>
 
<tr>
 
<td width="150">Primary Contact</td>
 
<td><input name="contact1" type="text" id="contact" size="50"></td>
 
</tr>
 
<tr>
 
<td width="150">Additional Contact</td>
 
<td><input name="contact2" type="text" id="contact2" size="50"></td>
 
</tr>
 
<tr>
 
<td width="150">Additional Contact</td>
 
<td><input name="contact3" type="text" id="contact3" size="50"></td>
 
</tr>
 
<tr>
 
<td width="150">Additional Contact</td>
 
<td><input name="contact4" type="text" id="contact4" size="50"></td>
 
</tr>
 
<tr>
 
<td width="150">General Description</td>
 
<td><input name="desc" size="50" type="text" id="desc"></td>
 
</tr>
 
 
<tr>
 
<td colspan="2"><br /><b>Please enter all the companies you represent with the products they provide:</b></td>
</tr>
 
<tr>
 
<td width="350">Company Represented</td>
 
<td>Products</td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[1]" type="text" size="30"></td>
 
<td><input name="product[1]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[2]" type="text" size="30"></td>
 
<td><input name="product[2]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[3]" type="text" size="30"></td>
 
<td><input name="product[3]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[4]" type="text" size="30"></td>
 
<td><input name="product[4]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[5]" type="text" size="30"></td>
 
<td><input name="product[5]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[6]" type="text" size="30"></td>
 
<td><input name="product[6]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[7]" type="text" size="30"></td>
 
<td><input name="product[7]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[8]" type="text" size="30"></td>
 
<td><input name="product[8]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[9]" type="text" size="30"></td>
 
<td><input name="product[9]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[10]" type="text" size="30"></td>
 
<td><input name="product[10]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[11]" type="text" size="30"></td>
 
<td><input name="product[11]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[12]" type="text" size="30"></td>
 
<td><input name="product[12]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[13]" type="text" size="30"></td>
 
<td><input name="product[13]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[14]" type="text" size="30"></td>
 
<td><input name="product[14]" type="text" size="75"></td>
</tr>
 
<tr>
 
<td><input name="name" type="hidden" value="<?php echo $myrow['name'] ?>"><input name="rep[15]" type="text" size="30"></td>
 
<td><input name="product[15]" type="text" size="75"></td>
</tr>
 
 
<tr>
 
<td>&nbsp;</td>
 
<td><input type="submit" name="submit" value="submit"></td>
</tr>
</table>
 
</form>
 
<?php
//}
} //end of else
?>
</body>
 
</html>
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: One Form Two Tables -- HELP

Post by califdon »

Every place in your script where you are issuing a mysql_query() command with an INSERT INTO SQL statement, insert a diagnostic to display what is wrong with your SQL, like this:

Code: Select all

mysql_query($result,$connect) or die(mysql_error());
The only way to learn what's going wrong is to enable all the debugging tools that are available, also including setting the PHP error reporting environment variables to show you all errors, at the beginning of your PHP code:

Code: Select all

ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);
kim5975
Forum Newbie
Posts: 2
Joined: Fri May 29, 2009 8:43 pm

Re: One Form Two Tables -- HELP

Post by kim5975 »

Thank you for your reply califdon :D I'll give it a whirl. I'm sure you can tell php is not my forte' :oops: Have a great day! Kim
Post Reply