-2

I am adding multiple languages to my custom CMS. I'm trying to have multiple language titles of the articles, based on the POSTed Language ID [language_id]. The $title_[$lid] should SET into DB's field a_title_[$lid]. I don't think I'm using a_title_[$lid] correctly. I would be immensely appreciative for any prompt help. I'm stuck in the water and under the gun.

$aid                = trim(cleanQuery($_POST[article_id]));
$lid                = trim(cleanQuery($_POST[language_id]));    
$title_[$lid]        = trim(cleanQuery($_POST[title_][$lid]));

mysql_query("UPDATE articles SET a_title_[$lid] ='$title_[$lid]' WHERE aid='$aid'"); 
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
Stipko
  • 13
  • 3
  • 1
    `a_title_[$lid]` - a field name!!!! – Sougata Bose Aug 07 '15 at 10:01
  • See http://php.net/manual/en/language.types.array.php (quoting literal keys) and http://php.net/manual/en/language.types.string.php#language.types.string.syntax.double (interpolation with `{}` curly syntax). Also rather curb the `cleanQuery()` compost and read up on [parameterization](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). – mario Aug 07 '15 at 10:01
  • Thanks b0s3. I realize a_title_[$lid] is not correct. Is there a better way to add the $lid variable to the a_title_ ? I know I'm just asking for a fix, and should be doing more background on this, but when I say I'm under the gun, I am really under the gun. I will do the homework when this hurdle is crossed. I swear. I always do. – Stipko Aug 07 '15 at 10:26

1 Answers1

0

I'm assuming that you don't want to use arrays but dynamic variables names. So if you want to have variables $title_1, $title_2, $title_3. You need to use {} like that:

${'title_' . $lid} = trim(cleanQuery($_POST['title_'][$lid])); // or maybe trim(cleanQuery($_POST['title_' . $lid]));

And your query should look like this:

mysql_query("UPDATE articles SET a_title_$lid ='${'title_' . $lid}' WHERE aid='$aid'"); 
arbogastes
  • 1,308
  • 9
  • 10