Forum Moderators: coopster
// Make the array
$bib_type = array ('mdbookclub, teen_bib, kids_bib');
// Check for a category.
if (($_POST['mdbookclub'] > 0)
OR ($_POST['teen_bib'] > 0) OR
($_POST['kids_bib'] > 0))
{
$bib_type = TRUE;
} else {
$bib_type = FALSE;
echo '<p><font color="red">Please select at least one category!</font></p>';
}
// Add the bib to the mdbookclub table.
if (is_array($_POST bib_type['mdbookclub'])) //if mother daughter bookclub selected
{
$query = "INSERT INTO mdbookclub (title, author, f_author, pub_year, annotation, call_number) VALUES (
'".mysql_escape_string($_POST['title'])."',
'".mysql_escape_string($_POST['author'])."',
'".mysql_escape_string($_POST['f_author'])."',
'".mysql_escape_string($_POST['pub_year'])."',
'".mysql_escape_string($_POST['annotation'])."',
'".mysql_escape_string($_POST['call_number'])."')";
if(!mysql_query($query) )
}
//Then I have the same for the other two tables substituting their table names.
The form is like this:
<p><strong>Please select a category:</strong>
<select name="bib_type">
<option value="mdbookclub">Mother Daughter Bookclub</option>
<option value="teen_bib">Teen Bibliography</option>
<option value="kids_bib">Kids Bibliography</option>
</select></p>
if (is_array($_POST bib_type['mdbookclub']))
Almost ... :)
More like:
if ($_POST['bib_type']==='mdbookclub') The form element being passed is 'bib_type'. It's value would be determined by the user selection.
Also, it's probably not a good idea to use a local variable with the same name as the form element ($bib_type). I'm not sure why you need that as an array to begin with.
How about:
if (!$_POST['bib_type']) { ... Select SOMEthing! ... and
<select name="bib_type"> <option value=0 />Please choose ... <option value="mdbookclub" />Moms & Daughters If they don't change the default item, that form element's value becomes 'false' (hence if NOT $_POST['bib_type']).
If the three tables are identical, or at least the columns you are inserting this data into are identical, then you can use:
$this_table=$_POST['bib_type']; INSERT INTO $this_table VALUES ... Hope that helps!
if ($_POST['bib_type']=='mdbookclub')
followed by
if (!$_POST['bib_type']) {
my INSERT query ....
It works great. You saved my day.