Am having a problem with my PHP. I have a for loop as below:
$todays_date = date("Y-m-d H:i:s");
for ($k=0; $k < $_SESSION[CampaignTrax]; $k++) {
$numIncrement = $k +1;
$artistConcentrate = '$_POST[ArtistField_'.$numIncrement.']';
$titleConcentrate = '$_POST[TitleField_'.$numIncrement.']';
$mixConcentrate = '$_POST[MixField_'.$numIncrement.']';
$query2 = "INSERT INTO trackdata (promo_ID, track_orderno, track_dateofcreation, track_artist, track_title, track_mix, track_promo_title) VALUES('$_SESSION[promo_ID]', '$numIncrement', '$todays_date', '{$artistConcentrate}', '$titleConcentrate', '$mixConcentrate', '$_SESSION[CampaignTitle]')";
mysql_query($query2) or die('Error in MySQL query. Here is the error message: '.mysql_error());
}
My problem is that the $artistConcetrate variable literally returns $_POST[ArtistField_1] and that value displays in the SQL table on PHPMyAdmin as so, any chance I can get it to actually return the value of what was submitted as POST[ArtistField_1], as this will be auto incremented through the loop so artistfield_2 etc will be inserted into the table.
I am aware of SQL injection problems that may occur from the above but will update my code after the solution has been found.
Many thanks for any advice on this.
CP
$_POST, not the entire PHP variable expression:$_POST['AritistField_' . $numIncrement]$queryin a loop and fire mysql_query only once after the loop with that$query..$_POST['ArtistField'][$numIncrement]? It's so much cleaner for you to work with, not to mention it's much simpler.