My IDE is expecting a semicolon but I'm not sure where! It is this line it is highlighting:
,'$other_writ' WHERE id="$_SESSION[user_id]")
This is the code above:
if (!empty($_POST['doLanguage']) && $_POST['doLanguage'] == 'Submit')
{
session_start();
foreach($_POST as $key => $value)
$id = "$_SESSION[user_id]";
if(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());
}
Thanks for any help!
You open a string here:
"INSERT into `language` ...
and it's being closed here:
... WHERE id="
PHP expects a semicolon after this. You could fix it by replacing the double quotes with single quotes (which are the SQL standard), but: why are you using a WHERE
clause with INSERT
anyway? You don't need that.
Just finish your string like this:
... ,'$other_writ')";
,'$other_writ' WHERE id=" . $_SESSION[user_id] . ")
So you missed a concatenation operator .
You need to change
,'$other_writ' WHERE id="$_SESSION[user_id]")";
to
,'$other_writ' WHERE id=" . $_SESSION[user_id] . ")";
I've seen this error
" WHERE id="$_SESSION[user_id]")";
you should use this way
" WHERE id=."$_SESSION[user_id].")";
also you have opened two curly parentheses but closed one.
Pretty sure you need a concatenation operator here:
WHERE id=" . $_SESSION[user_id] . ")";
Or like this:
WHERE id={$_SESSION[user_id]} )";
Your $sql_insert string should look like this. Pay attention right before the WHERE.
$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]}'";
Two things;
$_SESSION[user_id] is quoted with "
in the middle of a string that's in its entirety quoted with "
. The broken WHERE
part, being a bit misplaced in an INSERT
anyway, can be removed entirely.
Your for loop doesn't do much;
for($i = 0; $i < count($_POST["other"]); $i++);
The semicolon at the end makes it an empty loop. Remove it and things should work better.