I wonder whether someone can help me please.
I’m trying to put together a form and PHP script (below) which allows an administrator to search and update member details via the email address, populating a second email address, forename and surname fields with the retrieved information ready for them to be amended.
<?php
mysql_connect ("hostname","username","password") or die (mysql_error());
mysql_select_db ("databasename");
if ($_POST['search'])
{
$searchemailaddress = $_POST['searchemailaddress'];
$sql = mysql_query("select * from userdetails where emailaddress like '$searchemailaddress'");
while ($row = mysql_fetch_array($sql))
{
$emailaddress = $_POST['emailaddress'];
$forename = $row['forename'];
$surname = $row['surname'];
}
elseif ($_POST[['update'])
{
$userid = $_POST['userid'];
$emailaddress = $_POST['emailaddress'];
$forename = $_POST['forename'];
$surname = $_POST['surname'];
//replace TestTable with the name of your table
$sql = ("UPDATE `userdetails` SET `emailaddress` = '$emailaddress', `forename` = '$forename',`surname` = '$surname' WHERE `userdetails`.`userid` = '$userid' LIMIT 1");
}
}
}
?>
I’m receiving the following error:
Parse error: syntax error, unexpected T_ELSEIF in /homepages/2/d333603417/htdocs/development/searchandamend.php on line 13
with line 13 being this line in my script. elseif ($_POST[['update'])
Could someone perhaps take a look at this please and let me know where I’m going wrong.
Many thanks
The line
should have another
}afterwards. The one you have only closes thewhileloop. You also may want to consider using some indentation – that really helps seeing errors like this one.Also, the error basically says it all – the
else ifappears unexpectedly there, so the PHP processor expects something else (in this case a closing brace).