//$lottery=array(123-XYZ, 234-ABC, 456-DEF, ... , 678-GHI..., 400,000 random 123-ABC combinations)
// Set up the array
$final = $lottery;
// Connect to the database
$DB = mysql_connect("localhost", $db_user, $db_pass);
mysql_select_db($db_name, $DB);
// Create the query string
$query = '"INSERT INTO CustomerID (uniqueCustomerID) VALUES (';
// Loop through the array
for($i = 1, $c = count($final); $i < ($c-1); $i += 1) {
// Add the next batch of values to the query string
$query .= "'{$final[$i]}'";
// Add a comma if this is not the last batch
//make sure the correct php code is inserted here for the "if" loop condition {...}...else...
$query .= ", ";
}
$query .="'{$final[$c-1]}')".'"';
// Execute the query
$RESULT = mysql_query($query, $DB);
// Check the results
if(!!$RESULT) {
echo "Query was successfull";
}
else {
echo "Query failed
<blockquote>". $query ."</blockquote>
<blockquote>". mysql_error($DB) ."</blockquote>";
}
mysql_close($conn);
}
Query failed
"INSERT INTO CustomerID (uniqueCustomerID) VALUES ('434-BMJ', '670-XKR', '606-NYX',
'096-KUX', '143-XYJ', '681-YLV', '715-XZM', '822-UXN', '922-GIW', '958-ULQ',
'004-ICY', '102-CZO', '877-TJF', '681-CPQ', '498-LTS', '150-MOA', '113-DHB', ... ,
'237-QIS', '244-KOG', '241-TKK', '087-GNN', '298-DQX', '492-YGR', '454-PCQ',
'065-WIB', '235-AKW', '973-ZQD', '640-DUI', '248-YYW', '575-OSN', 134-XUQ',
'087-EEL', '037-HVN', '111-QHY')"
You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '"INSERT INTO
CustomerID (uniqueCustomerID) VALUES ('434-BMJ', '670-XKR', '606-NY' at line 1
Above shows my response from the snippet of code I have been working with over the past two days. I cannot figure this one out, I keep receiving an error when attempting to insert my array full of data into my already initiated MySql database. It’s telling me that there is a syntax error within MySql code I have… I have not been able to figure it out after two days…
Could someone lend me a hand?