Hey.
First of all, your
foreach loop is - undoubtedly - not working as you want it to. Anything that should belong to a loop should be put inside brackets following the loop.
If the
foreach is not followed by brackets ({}), it will assume only the very first line following it belongs to the loop. Therefore you should ALWAYS use brackets. Even if there is only one line. (For the sake of consistency)
- <?php
-
// Some random values to loop through.
-
$values = array("first", "second", "third");
-
-
// This only prints one value: "third"
-
foreach($values as $_value)
-
$value = $_value; // This is inside the loop
-
echo $value; // This is OUTSIDE the loop.
-
-
// This prints all three values.
-
foreach($values as $_value) {
-
$value = $_value;
-
echo $value;
-
}
-
?>
Also, you should verify that the data is valid before using it in the query. Make sure the values you are using aren't empty, and that they contain the data you expect them to contain.
And as always, when dealing with MySQL queries: run ALL values through
mysql_real_escape_string before putting it into the query. Otherwise your database is open for SQL Injection attacks.
(If you think the data you are using is secure... you are wrong! :P)