Hello,
I have three tables in MySQL database which they are: employee, expenses and details. The details table is composite table between the expenses and employee. In the HTML form there is a table that will enter multiple data into details that will referenced with one expenses id. I could only insert one values from the row and did not insert the second row values. Could anyone help me or suggest a solution for me.

    $exp_id = mysql_insert_id();
    $query2 ="INSERT INTO expenses_claim (claimant_date,total_bd) VALUES (now(), '$total')";
    $result = mysql_query ($query2,$connect);
    $last_insert_exp_id = mysql_insert_id();
    $query3 = "Insert INTO details (exp_id, emp_no, manager_no, exp_desc, amount, foreign_currency, exch_rate, BD) VALUES ('$last_insert_exp_id','$emp_no','$manager_no','$exp_desc1','$amount1','".$_POST['select']."','$exch_rate1', '$bd1')"; 
    $result1 = mysql_query($query3,$connect); 
Member Avatar for LastMitch

I have three tables in MySQL database which they are: employee, expenses and details. The details table is composite table between the expenses and employee. In the HTML form there is a table that will enter multiple data into details that will referenced with one expenses id. I could only insert one values from the row and did not insert the second row values. Could anyone help me or suggest a solution for me.

@Nadera

You need to post your div tags so it would be easier to grasp with the query code.

Right now, it just guessing which query is coming from which html code.

I am trying to save multiple data into the database. When I select committee, it displays the ID and email of the members who represent the committee. How can I save those email addresses based on the committee in the database? Please help me.

<?php
require "config.php"; // Your Database details 
@$cat=$_GET['cat']; 
@$cat3=$_GET['cat3']; 
error_reporting(0);
?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>

<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value; 
self.location='test.php?cat=' + val ;
}
function reload3(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value; 
var val2=form.subcat.options[form.subcat.options.selectedIndex].value; 

self.location='test.php?cat=' + val + '&cat3=' + val2 ;
}

</script>
</head>

<body>
<?Php


// Getting the data from Mysql table for first list box//
$quer2="SELECT DISTINCT committee FROM member order by committee"; 
// End of query for first list box//

// for second drop down list we will check if category is selected else we will display all the subcategory//
$cat=$_GET['cat']; // This line is added to take care if your global variable is off
if(isset($cat) and strlen($cat) > 0){
$quer="SELECT DISTINCT member_id FROM member where committee=$cat order by member_id"; 
}else{$quer="SELECT DISTINCT member_id FROM member order by member_id"; } 
// end of query for second subcategory drop down list box //


// for Third drop down list we will check if sub category is selected else we will display all the subcategory3///
$cat3=$_GET['cat3']; // This line is added to take care if your global variable is off
if(isset($cat3) and strlen($cat3) > 0){
$quer3="SELECT DISTINCT member_id FROM member where committee=$cat3"; 
}else{$quer3="SELECT DISTINCT member_email FROM member order by member_email"; } 
// end of query for third subcategory drop down list box //


echo "<form method=post name=f1 action=''>";
//Starting of first drop downlist //
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select Committee</option>";
foreach ($dbo->query($quer2) as $noticia2) {
if($noticia2['committee']==@$cat){echo "<option selected value='$noticia2[committee]'>$noticia2[committee]</option>"."<BR>";}
else{echo  "<option value='$noticia2[committee]'>$noticia2[committee]</option>";}
}
echo "</select>";
//  This will end the first drop down list //

//Starting of second drop downlist //
echo "<select name='subcat' onChange=AjaxFunction(); multiple size=7 style='width:150'\"><option value=''>Member ID</option>";
$sql="select member_id, member_email from member where committee='$cat' ";
foreach ($dbo->query($sql) as $row) {
echo "<option value=$row[member_id]>$row[member_id]</option>";
}
echo "</select>";
// This will end the second drop down list //


//Starting of third drop downlist //
echo "<select name='subcat3'  onChange=AjaxFunction(); multiple size=7 style='width:250'\"><option value=''>Member Email</option>";
$sql="select member_email from member where committee='$cat' ";
foreach ($dbo->query($sql) as $row) {
echo "<option value=$row[member_email]>$row[member_email]</option>";
}
echo "</select>";
//  This will end the third drop down list //

?>


<br><br>
<label for="text3">Subject:</label>

          <input type="text" name="subject" maxlength="100" id="subject" size="50"><br/><br/>
          <label for="text3">Message:</label>

           <input type="text" name="message" maxlength="100" id="subject" height="40" size="100"><br/><br/>

           <label for="text4"> Attachment:</label>
           <input type="hidden" name="MAX_FILE_SIZE" value="20000000" />

  <input id="userfile" type="file" name="userfile" />
</p>


  <input id="upload" type="submit" name="upload" value="Send"/>
</p></form></p>


        <?php


             $subcat=$_POST['subcat'];  
             $subcat3=$_POST['subcat3'];             
             $subject=$_POST['subject'];
             $message=$_POST['message'];

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)

{

$fileName = $_FILES['userfile']['name'];

$tmpName  = $_FILES['userfile']['tmp_name'];

$fileSize = $_FILES['userfile']['size'];

$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');

$content = fread($fp, filesize($tmpName));

$content = addslashes($content);

fclose($fp);

if(!get_magic_quotes_gpc())

{

$fileName = addslashes($fileName);

}
$cat=$_POST['cat'];

$con=mysqli_connect("localhost","root","","system_meeting");

//mysqli_select_db($con, "upload");

$query = "INSERT INTO admin_member VALUES('','$login_session','$subcat','$subcat3','$user_check','$subject','$message','$fileName','$fileSize','$fileType','$content', now(), '$cat')";
mysqli_query($con, $query) or die('Error, query failed');

echo ("<font color='#000000'> Message Successfully Sent</font>");

}

?>
<a href=test.php>Reset</a>
</body>
</html>
<br><br>
</body>
</html>
Member Avatar for diafol

Please start your own thread. This has been dead for 2 years.
In addition - please tidy up your code/markup before doing so. It's all over the place. Mish-mashed html and php.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.