In my code, if get a list of subjects separated by ";", I then make that string into an array with explode, and try to add a row to the database for every subject. But i get "Unable to insert subjects to database" every time i run it.
Expand|Select|Wrap|Line Numbers
- //Explode the subjects string into seperate subjects
- $subjects = $_POST["article_subjects "];
- $subjects_arr = explode(';', $subjects, 10);
- for ($i = 0; $i <= 10; $i++) {
- if ($subjects_arr[$i] != null){
- $add_subject_sql = "INSERT INTO artikel_subject (artikel_id, artikel_subject) VALUES ('".$article_id."','".$subjects_arr[$i]."')";
- $add_subject_res = mysql_query($add_subject_sql) or die("Unable to insert subjects to database");
- }
- }
Expand|Select|Wrap|Line Numbers
- $add_subject_sql = "INSERT INTO artikel_subject (artikel_id, artikel_subject) VALUES ('".$article_id."','".$_POST["article_subject"]."')";