Can anyone please help.I am trying to add values to a table from 2 dropdown lists which are dynamically poulated.
I have managed to achieve it for one drop list but have added a second and cannot create the correct syntax to add both values to the table.
// Check for a URL.
if (eregi ('^([[:alnum:]\-\.])+(\.)([[:alnum:]]){2,4}([[:alnum:]/+=%&_\.~?\-]*)$', $_POST['url'])) {
$u = escape_data($_POST['url']);
} else {
$u = FALSE;
echo '<p><font color="red">Please enter a valid URL!</font></p>';
}
// Check for a URL title.
if (!empty($_POST['title'])) {
$t = escape_data($_POST['title']);
} else {
$t = FALSE;
echo '<p><font color="red">Please enter a URL name/title!</font></p>';
}
// Check for a URL date.
if (!empty($_POST['pub_date'])) {
$p = escape_data($_POST['pub_date']);
} else {
$p = FALSE;
echo '<p><font color="red">Please enter a date!</font></p>';
}
// Check for a description.
if (!empty($_POST['description'])) {
$d = escape_data($_POST['description']);
} else {
$d = FALSE;
echo '<p><font color="red">Please enter a description!</font></p>';
}
// Check for a publisher.
if (isset($_POST['posters']) && (is_array($_POST['posters']))) {
$poster = TRUE;
} else {
$poster = FALSE;
echo '<p><font color="red">Please choose a Publisher!</font></p>';
}
// Check for a category.
if (isset($_POST['types']) && (is_array($_POST['types']))) {
$type = TRUE;
} else {
$type = FALSE;
echo '<p><font color="red">Please choose a Client!</font></p>';
}
if ($u && $t && $d && $p && $type && $poster) { // If everything's OK.
// Add the URL to the urls table.
$query = "INSERT INTO urls (url, title, description, pub_date) VALUES ('$u', '$t', '$d', '$p')";
$result = @mysql_query ($query); // Run the query.
$uid = @mysql_insert_id(); // Get the url ID.
if ($uid > 0) { // New URL has been added.
// Make the URL associations.
// Build the query.
$query = 'INSERT INTO url_associations (url_id, url_category_id, approved, url_publisher_id) VALUES ';
foreach (($_POST['types'] as $v) AND ($_POST['posters'] as $k)){ //This is line I am having issues with
$query .= "($uid, $v, 'Y', '$k'), ";
}
$query = substr ($query, 0, -2); // Chop off the last comma and space.
$result = @mysql_query ($query); // Run the query.
if (mysql_affected_rows() == count($_POST['types']) AND ($_POST['posters'])) { // I also suspect this will give me issues too.
echo '<p><b>Thank you for your submission!</b></p>';
$_POST = array(); // Reset values.
} else { // If second query did not run OK.
echo '<p><font color="red">Your submission could not be processed due to a system error. We apologize for any inconvenience.</font></p>'; // Public message.
Any assistance would be gratefully accepted. Kind regards.
Sean