-1

I have a myaccount page which a user logs into. From this the user can click on another form 'Language' table. When submitted it take them back to their account. This is the code I have so far but getting the error Parse error: syntax error, unexpected '='.

if (!empty($_POST['doLanguage']) && $_POST['doLanguage'] == 'Submit') 
 { 
  foreach($_POST as $key => $value) 
   id = '$_SESSION[user_id]';

$host  = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$path   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');


(empty($err)) {
for($i = 0; $i < count($_POST["other"]); $i++)
{
  $native = mysql_real_escape_string($_POST['native'][$i]);
  $other = mysql_real_escape_string($_POST['other'][$i]);
  $other_list = mysql_real_escape_string($_POST['other_list'][$i]);
  $other_read = mysql_real_escape_string($_POST['other_read'][$i]);
  $other_spokint = mysql_real_escape_string($_POST['other_spokint'][$i]);
  $other_spokprod = mysql_real_escape_string($_POST['other_spokprod'][$i]);
  $other_writ = mysql_real_escape_string($_POST['other_writ'][$i]);

  $sql_insert = "INSERT into `language`
  (`native`,`other`,`other_list`,`other_read`, `other_spokint`
  ,`other_spokprod`,`other_writ`            )
  VALUES
  ('$native','$other','$other_list','$other_read','$other_spokint',
  '$other_spokprod'
  ,'$other_writ'  WHERE id='$_SESSION[user_id]
        )
        ";
mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());     
    }


echo('<a href="myaccount.php?id=' . $_SESSION['id'] . '">link</a>');
exit();

 } 
}

Please help!

user1257518
  • 153
  • 6
  • 17
  • 1
    in your fourth line you forgot $ it should be `$id`. – flo Mar 27 '12 at 14:09
  • You have a lot of syntax errors there, looks like bits of different code samples copied. Try using an [IDE](http://stackoverflow.com/questions/116292/what-is-the-best-ide-for-php). – Shomz Mar 27 '12 at 14:15
  • Also, in addition to what @flo said, you don't need quotes in the line 4, and it might be a good idea to use curly braces with that `foreach`... This way it's useless. – Shomz Mar 27 '12 at 14:16
  • what is the whole essence of foreach($_POST as $key => $value) ??? what are you trying to achieve – Baba Mar 27 '12 at 14:17
  • is it required to use `exit` at the end of the script... ? – evotopid Mar 27 '12 at 14:36
  • when changing to curly brackets I get 'expecting )' – user1257518 Mar 27 '12 at 15:05
  • Can anyone see why I'm now getting this error 'unexpected T_VARIABLE' with this line $sql_insert = "INSERT into `language` ("$native","$other","$other_list","$other_read","$other_spokint", "other_spokprod" ,"$other_writ" WHERE id="$_SESSION[user_id]" ) "; – user1257518 Mar 27 '12 at 15:08

1 Answers1

4

Change id = '$_SESSION[user_id]'; to $id = $_SESSION['user_id'];

slash197
  • 8,880
  • 6
  • 40
  • 68
  • and make sure you use `session_start();` on the page! – Nick Mar 27 '12 at 14:13
  • Thanks! Now im getting unexpected ')' in C:\xampp\htdocs\euisample\language.php - which is this line ** ('$native','$other','$other_list','$other_read','$other_spokint','$other_spokprod','$other_writ'where id='$id'") or die(mysql_error());** – user1257518 Mar 27 '12 at 14:34
  • If you place variable between single quotes they won't be parsed, use double qoutes `"` – slash197 Mar 27 '12 at 14:41