This is Sooooo CLOSE! And yet…
follow comments:
[code=php]<?php # Script test_canvas_list.php
if (isset($_POST[‘submit’])) { // Handle the form.
require_once (‘mysql_connect.php’); // Connect to the db.
mysql_select_db (‘crm’) OR DIE (“Could Not select database’crm’:” . MYSQL_ERROR());
$canvas_list_contacts =” select id from contacts where agency_name=’FSBO’ and first_name=’tj'”;
$result = @mysql_query ($canvas_list_contacts)or die (“Query failed”); // Run the query.
// narrow query paramaters for single result and convert result set into array
$array = array();
while ($row = mysql_fetch_assoc($result)) {
$array[] = $row[id];
}
$targets = array();
foreach ($array as $value)
{
$targets[] = “(”,’4c1c90ac-e29d-b079-8c24-4550f759e92c’,’$value’,’Contacts’,’null’,’null’)”;
}
echo ‘<select name=”endDate”>’;
foreach ($targets as $key => $value) {
echo “<option value=”$key”>
$value</option>n”; // echos infinite $targets array string values in dropdown as expected.
}
echo ‘</select><br><br>’;
$populate_canvas_list = “INSERT INTO prospect_lists_prospects (id,prospect_list_id,related_id,related_type,date_modified,deleted)
VALUES (”, ‘4c1c90ac-e29d-b079-8c24-4550f759e92c’,”,’Contacts’,”,”),
(‘1’, ‘4c1c90ac-e29d-b079-8c24-4550f759e92c’,”,’Contacts’,”,”),
(‘2’, ‘4c1c90ac-e29d-b079-8c24-4550f759e92c’,”,’Contacts’,”,”)”; //Everything works to this point – BUT…
//(‘2’, ‘4c1c90ac-e29d-b079-8c24-4550f759e92c’,’$value’,’Contacts’,”,”)”; //Query fails using ‘$value’
//VALUES .implode(‘, ‘, $targets)”; // Closing double_quote causes error, unexpected ‘”‘
VALUES .implode(‘, ‘, $targets); // Remove closing double_quote returns: ‘Query failed:’ ‘”‘
mysql_query($populate_canvas_list) or die(‘Query failed: $populate_canvas_list – . mysql_error()’);
}
exit(); // Quit the script.
mysql_close(); // Close the database connection.
?>