我在设计这个网站时遇到问题,在我睁大眼睛之前寻求帮助。以下脚本的预期结果是一个网页,其输入表单应如下所示(使用
James Craig | Week 7 | <INPUT>max</INPUT | <INPUT>ctrl</INPUT>
Jo Mama | Week 7 | <INPUT>max</INPUT | <INPUT>ctrl</INPUT>
但是,我实际看到的是:
James Craig Week 7 max: ctrl:
没有文本输入字段,也没有表格格式。此外,它没有显示第二人称。
然后:页面锁定并使浏览器崩溃。
我怀疑我的循环没有结束,但此时我已经迷失了。我知道有很多问题要问,但是有人可以在这里理顺我吗?:)
我正在使用的基本数据:
数据库样本数据
Table Name: loginUsers
--------------------------------------------------------
| storeID | login | password |
|-------------------|----------------|-----------------|
| 0460 | store0460 | store0460 |
--------------------------------------------------------
Table Name: specialistData
--------------------------------------------------------
| specialistID | week | max | ctrl |
|------------------------------------------------------|
| 1 | 1 | 28.50 | 19.99 |
| 1 | 2 | 17.85 | 21.99 |
| 1 | 3 | 16.99 | 99.99 |
| 1 | 4 | 28.50 | 19.99 |
| 1 | 5 | 28.50 | 19.99 |
| 1 | 6 | 28.50 | 19.99 |
| 2 | 1 | 28.50 | 19.99 |
| 2 | 2 | 17.85 | 21.99 |
| 2 | 3 | 16.99 | 99.99 |
| 2 | 4 | 28.50 | 19.99 |
| 2 | 5 | 28.50 | 19.99 |
| 2 | 6 | 28.50 | 19.99 |
--------------------------------------------------------
Table Name: usersSpecialists
--------------------------------------------------------
| storeID | specialistID | name |
|-------------------|----------------|-----------------|
| 0460 | 1 | James Craig |
| 0460 | 2 | Jo Mama |
--------------------------------------------------------
有问题的 PHP 文档(我删除了 DB 连接字符串,但我向您保证它们工作正常)
<?php
//Initialize the session
session_start();
//Check for existing session. Route to login if not
if(!isset( $_SESSION['username'])){
header('Location: ../index.php');
}
?>
<?php include(dirname(__FILE__)."/functions.php"); ?>
<html>
<head>
<title>Weekly Data</title>
<link href="portal.css" rel="stylesheet">
</head>
<body>
<div id="masthead">
<ul class="nav nav-pills pull-right">
<li class = "active"><a href="#">View Report</a></li>
<li class = "active"><a href="#">Edit Specialists</a></li>
<li class = "active"><a href="logout.php">Logout</a></li>
</ul>
<h3 class="muted">Sales Specialist Ranker - Weekly Data</h3>
</div>
<hr>
<div id="jumbotron"><center>
<h1>Enter Weekly Data</h1>
<form action="submitData.php method="GET">
</form>
<a class="btn btn-large btn-success" href="#">Submit</a>
</center></div>
<?php
//This will determine the current week, compare it to the last entry for each specialist, and create a form to request any needed data.
//Obtain currently logged in store (Store Number)
$currentStore = $_SESSION['username'];
//Obtain Current Week
$currentWeek = date("W");
//Obtain list of specialists (specialist ID)
//Create temp mysqli object
$specialistList = new mysqli();
//Grab specialist list
$specialistList = getSpecialists($currentStore);
//Loop through each specialist and generate form
//Start Form
echo "<form name='specialistData' action='submitData.php' method='get'>";
//Start Loop
while($row = $specialistList->fetch_array(MYSQLI_ASSOC)){
//Start HTML Table
echo "<table class='dataEntry'>";
//create temp mysqli object
$lastWeek = new mysqli();
//Get last entry for specialist
$lastWeekData = lastEntry($row['specialistID']);
$lastWeekData = $lastWeekData->fetch_array(MYSQLI_ASSOC);
$lastWeek = $lastWeekData['week'];
$specialistID = $row['specialistID'];
$specialistName = $lastWeekData['name'];
//compare last week to current week
//Begin loop
while($lastWeek < $currentWeek){
//create HTML Input for each specialist
echo "<tr>\n
<td>$specialistName</td>\n
<td>Week: $lastWeek</td>\n
<td>Max: <input type='text' name='".$specialistID."-".$lastWeek."-max /></td>\n
<td>Max: <input type='text' name='".$specialistID."-".$lastWeek."-ctrl /></td>\n
</tr>\n";
$lastweek++;
}
//Close HTML table for this specialist
echo "</table>";
}
//Close HTML Form
echo "</form>";
?>
<hr>
<div class="footer">
<p> Footer Here</p>
</div>
</body>
</html>
这是我的functions.php
<?php //FUNCTIONS
function getSpecialists($user){
/*
PURPOSE: GET LIST OF SPECIALISTS THAT BELONG TO CURRENT USER
ARGUMENTS: $user{USER ID - STRING}
RETURN: MYSQLI OBJECT CONTAINING RESULT LIST {specialistID}
*/
//Include DB Strings
$DB_HOST = "****";
$DB_NAME = "****";
$DB_USER = "****";
$DB_PASS = "****";
//Query create the SQL object
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
//Plan for error
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n". mysqli_connect_error(error)." \n WHEN: OBTAINING SPECIALIST LIST");
exit();
}
//Create QUERY to return {specialistID}
$sql = "SELECT usersSpecialists.specialistID
FROM usersSpecialists
INNER JOIN loginUsers
ON usersSpecialists.storeID = loginUsers.storeID
WHERE loginUsers.login = '$user'";
//Launch the query
$specialistResults = $mysqli->query($sql);
//Send back results of query
return $specialistResults;
}
function lastEntry($specialist){
/*
PURPOSE: GET THE LATEST ENTRY (WEEK NUMBER) FOR GIVEN SPECIALIST
ARGUMENTS: $specialistID{SPECIALIST IN QUESTION - INT}
RETURN: MYSQLI OBJECT CONTAINING RESULT LIST {week, name}
*/
//Include DB connection strings
$DB_HOST = "****";
$DB_NAME = "****";
$DB_USER = "****";
$DB_PASS = "****!";
//Query create the SQL object
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
//Plan for error
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n". mysqli_connect_error(error)." \n WHEN: OBTAINING SPECIALIST LIST");
exit();
}
//Create SQL query
$sql = "SELECT specialistData.week, usersSpecialists.name
FROM specialistData
INNER JOIN usersSpecialists
ON specialistData.specialistID = usersSpecialists.specialistID
WHERE specialistData.specialistID = $specialist
ORDER BY specialistData.week DESC
LIMIT 1";
//Launch SQL query
$lastWeek = $mysqli->query($sql);
//Return mysqli result $lastWeek {week, name}
return $lastWeek;
}
?>