Guys can you please help me with this piece of code?
I dont undestand why it runs the SQL twice :
foreach ($_POST as $key => $value){
$$key = $_POST[$key];
if(preg_match($pattmusic , $key, $matches, PREG_OFFSET_CAPTURE)){
if(preg_match($pattmusicStyle , $key, $matches, PREG_OFFSET_CAPTURE)){
$style = $value;
}elseif(preg_match($pattmusicSinger, $key, $matches, PREG_OFFSET_CAPTURE)){
$singer= $value;
if(!empty($style ) && !empty($singer)) {
$insert_qr = "INSERT INTO album (albumID, singer, style) VALUES( '".$singer."', '".$style."')";}
}
mysql_select_db($database_dbConnect, $dbConnect);
mysql_query($insert_qr, $dbConnect) or die(mysql_error());
I have 3 patterns:
$pattmusic = '/music/';
$pattmusicStyle = '/music_Style/';
$pattmusicSinger = '/music_Singer_/';
to enter the condition it first checks if it is from the MUSIC group... then it divides in two subcategories... music style and music instrument.
and in the last conditional it assigns the value to the query variable to be executed.. but its being executed and inserting the same record twice.
In this form... I have pairs of fields that has to be inserted both at the same time... because the user can add more field pairs on the fly with javascript..:
Music Style Music Instrument
{field 1} {field 1}
{field 2} {field 2}
Thanks for you help 🙂