Jump to content

Inserting into multiple tables and multiple entries


cdoggg94

Recommended Posts

I have a form that looks like this:

 

<form name="form" action="multiCheck2.php" method="POST" enctype="multipart/form-data">
	<table width="381" border="0">
    	<tr>
        	<td colspan="2">Dates Name: <input name="name" type="text" size="39" /></td>
        </tr>
        <tr>
        	<td>Date: <input name="date" type="text" /></td>
            <td> Time: <input name="time" type="text" /></td>
        </tr>
        <tr>
        	<td colspan="2">Additional Information:<br />
       	    <textarea name="comments" cols="45" rows="7"></textarea></td>
        </tr>
    	<tr>
        	<td>
            
            	Whos is this for ? <br />
              
              <p>
              <label>
                <input type="checkbox" name="who[]" value="Coaches" />
                Coaches</label>
              <br />
              <label>
                <input type="checkbox" name="who[]" value="Conveners" />
                Conveners</label>
              <br />
              <label>
                <input type="checkbox" name="who[]" value="Officials" />
                Officials (Both)</label>
                <br />
              <label>
                <input type="checkbox" name="who[]" value="Ref" />
                Ref</label>
                <br />
              <label>
                <input type="checkbox" name="who[]" value="Linesmen" />
                Linesmen</label>
              <br />
              <label>
                <input type="checkbox" name="who[]" value="Admin" />
                Admin</label>
              <br />
              <label>
                <input type="checkbox" name="who[]" value="All" />
                All</label>
              <br />
            </p>
            
            
            </td>
            <td valign="bottom" align="right">
            
            <br /><br />
          <input name="submit" type="submit" value="ADD UPDATE" /></td>
        </tr>
	</table>
	<input type="hidden" name="MM_insert" value="form" />
</form>

 

I have 2 tables I want to interact with.  One is called "soccer_dates" and the other is called "soccer_dates_who".

 

I want soccer_dates to take the values (without the date_who) and insert that information. I have this working fine...

 

In the soccer_dates_who, I want to take the new ID from the newly created soccer_dates entry and insert it, along with the the value from the checked boxes.

 

Also, if there is more then one box checked, i want to make it so there is a new entry in soccer_dates_who for each checked box..

I have been working on this for a few days and but biggest issue is getting the new ID from soccer_dates and putting it into the new table all in one go.  I can do it in 2 different pages, but it adds an extra step.

Does anyone have any advice ? Im not really even sure what to look up for examples..

I have it working like this:

 

<?php
mysql_query("INSERT INTO soccer_dates (date_id, date_name, date_date, date_time, date_content, date_email)
VALUES ('', '".$_POST['name']."', '".$_POST['date']."','".$_POST['time']."','".$_POST['comments']."','')");

$parent = mysql_insert_id();
//$whoCat = print_r($_POST['who']);
//$whoCat = substr(implode(‘, ‘, $_POST['tags']), 0);

foreach($_POST['who'] as $option_key => $option_name)
{
mysql_query("INSERT INTO soccer_dates_who (who_id, who_parent, who_who)
VALUES ('', '".$parent."', '".$option_name."')");
}



echo "<br /><br />Thank you for uploading<br /><br />";



?>

 

Everything seems to be inserting correctly in both tables.

 

Is this a good way of doing it ? or is there an obvious flaw ?

 

Im just happy right now that it's working...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.