いくつかのエラーを確認しましたが、以下で修正しました。
これは私が誤っていると得たものです:
if (login())
{?>
<h2>Welcome Administrator</h2>
<a href=\"upload.php\">Upload Files</a>
<br />
<a href=\"points.php\">Edit Points Tally</a>
<?php}
else
{
echo "Incorrect login details. Please login";
}
これは私がそれをした方法です:
<html>
some code
<?php
function login()
{
if (empty ($_POST['username']))
{
return false;
}
if (empty ($_POST['password']))
{
return false;
}
$username = trim ($_POST['username']);
$password = trim ($_POST['password']);
$scrambled = md5 ($password . 'foo');
$link = mysqli_connect('localhost', 'root', 'password');
if (!$link)
{
$error = "Unable to connect to the database server";
include 'error.html.php';
exit ();
}
if (!mysqli_set_charset ($link, 'utf8'))
{
$error = "Unable to set database connection encoding";
include 'error.html.php';
exit ();
}
if (!mysqli_select_db ($link, 'foo'))
{
$error = "Unable to locate the foo database";
include 'error.html.php';
exit ();
}
$sql = "SELECT COUNT(*) FROM admin WHERE username = '$username' AND password = '$scrambled'";
$result = mysqli_query ($link, $sql);
if (!$result)
{
return false;
exit ();
}
$row = mysqli_fetch_array ($result);
if ($row[0] > 0)
{
return true;
}
else
{
return false;
}
}
if (login())
{
echo '<h2>Welcome Administrator</h2>
<a href=\"upload.php\">Upload Files</a>
<br />
<a href=\"points.php\">Edit Points Tally</a>';
}
else
{
echo "Incorrect login details. Please login";
}
?>
some more html code
</html>