I keep getting this error everytime i try to run my code:
Parse error: parse error, unexpected $end in C:\wamp\www\testsite\users.php on line 161
here is my users.php code:
<?php
function showUsers()
{
?>
<center>
<br><b>Registered Users</b><br><br>
<a href="mysqlcore.php?cmd=addUser">Add User</a>
<br><br>
<table width="450" border="1" cellpadding="4">
<tr bgcolor="#BBBBBB">
<td width="25%"><b>Name</td>
<td width="25%"><b>Age</td>
<td width="25%"><b>Allias</td>
<td width="25%"><b>Password</td>
<td width="25%"><b>Edit</td>
<td width="25%"><b>Delete</td>
</tr>
<?php
$dbh = mysql_connect("localhost", "root", "");
mysql_select_db("phptest", $dbh);
$results = mysql_query("SELECT * FROM users ORDER BY name", $dbh);
while($row = mysql_fetch_array($results))
{
print "<tr>";
print "<td>".htmlspecialchars($row["name"])."</td>";
print "<td>".htmlspecialchars($row["age"])."</td>";
print "<td>".htmlspecialchars($row["alias"])."</td>";
print "<td>".htmlspecialchars($row["password"])."</td>";
print "<td><input type=\"button\" value=\"Edit\"
onClick=\"window.location = 'mysqlcore.php?cmd=
adduser&id=".$row["id"]."';\"></td>";
print "<td><input type=\"button\" value=\" Delete\"
onClick=\"window.location = 'mysqlcore.php?cmd=
deleteuser&id=".$row["id"]."';\"></td>";
print "</tr>";
}
mysql_close($dbh);
?>
</table>
</center>
<?php
function addUser()
{
$id = $_GET["id"];
if($id != "")
{
$dbh = mysql_connect("localhost", "root", "");
mysql_select_db("phptest", $dbh);
$results = mysql_query("SELECT * FROM users WHERE id =
'$id'", $dbh);
if ($row = myql_fetch_array($results))
{
$name = $row["name"];
$age = $row["age"];
$alias = $row["alias"];
$password = $row["password"];
}
mysql_close($dbh);
}
?>
<center>
<br><b>
<?php
if($id == "")
print "Add User Form";
else
print "Edit User Form";
?>
</b><br><br>
<form method="POST" action="mysqlcore.php">
<input type="hidden" name="cmd" value="doAddUser">
<input type="hidden" name="id" value="<?php print $id; ?>">
<table width="450" border="1" cellpadding="4">
<tr>
<td>Name:</td>
<td><input type="text" name="name" value=
"<?php print $name; ?>"></td>
</tr>
<tr>
<td>Age:</td>
<td><input type="text" name="age" size=3 value=
"<?php print $age; ?>"></td>
</tr>
<tr>
<td>Allias:</td>
<td><input type="text" name="alias" value=
"<?php print $alias; ?>"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" value=
"<?php print $password; ?>"></td>
</tr>
</table>
<br><br>
<input type="submit" value="<?php
if($id == "")
print "Add User";
else
print "Save Changes";
?>">
<input type="button" value="Cancel" onClick="window.location='mysqlcore.php'">
</form>
<?php
}
function doAddUser()
{
$id = $_POST["id"];
$dbh = mysql_connect("localhost", "root", "");
mysql_select_db("phptest", $dbh);
if($id == "")
mysql_query("INSERT INTO users VALUES (NULL,
\"".$_POST["name"]."\", \"".$_POST["age"]."\",
\"".$_POST["alias"]."\", \"".$_POST["password"]."\")", $dbh);
else
{
mysql_query("UPDATE users SET name = \"".$_POST["name"]."\", age
=\"".$_POST["age"]."\", alias = \"".$_POST["alias"]."\",
password = \"".$_POST["password"]."\" WHERE id = '$id'",
$dbh);
}
mysql_close($dbh);
header("Location: mysqlcore.php");
}
function deleteUser()
{
$id = $_GET["id"];
$dbh = mysql_connect("localhost", "root", "");
mysql_select_db("phptest", $dbh);
mysql_query("DELETE FROM users WHERE id= '$id'", $dbh);
mysql_close($dbh);
header("Location: mysqlcore.php");
}
?>
Here is my mysqlcore.php:
<?php
include("header.php");
include("footer.php");
include("users.php");
switch($_POST['cmd'])
{
case "doAddUser":
doAddUser();
exit();
case "deleteuser":
deleteUser();
exit();
}
showHeader();
switch($_GET['cmd'])
{
case "addUser":
addUser();
break;
default:
showUsers();
break;
}
showFooter();
?>
I dont understand i went over the code and I just cant find it.
Line 161 of my code is ending the php code "?>"
plz help me & thanks. :bemused: