如标题所示,我有一个页面供用户创建项目,另一个页面将其添加到我的数据库中。但是,当我按表单字段为空时按提交时,它发布到的页面不是空白。但是当我提交填写的字段时,它只显示一个没有任何错误的空白页面,我查看了两个代码页但似乎找不到任何错误。也许这里有人可以帮助我?感谢。
//提交数据的页面上的代码。
if ($_POST['projectTitle'] != "" && $_POST['projectStatus'] != "" && $_POST['projectDesc'] != "" && $_POST['projectDeliv'] != "" && $_POST['year'] != "" && $_POST['month'] != "" && $_POST['day'] != "" && $_POST['projectSS'] != "") {
$host = "localhost";
$user = "root";
$pass = "";
$db = "fyp1";
$pt = $_POST['projectTitle'];
$ps = $_POST['projectStatus'];
$pdes = $_POST['projectDesc'];
$pdel = $_POST['projectDeliv'];
$date = $_POST['year'] . "-" . $_POST['month'] . "-" . $_POST['day'];
$pss = $_POST['projectSS'];
date_default_timezone_set('UTC+8');
$cDate = date('Y-m-d');
$uid = $_SESSION['id'];
$link = mysqli_connect($host, $user, $pass, $db) or die(mysqli_error());
$query = "SELECT * FROM project WHERE project_title = $pt AND project_description = $pdes AND project_deliverables = $pdel AND project_skillset = $pss";
$dub = mysqli_query($link, $query) or die(mysqli_connect_error($link));
if (mysqli_num_rows($dub) == 0) {
$insertQ = "INSERT INTO project(project_title,project_description,project_deliverables,project_start,project_end,project_skillset,project_status)
VALUES ('$pt','$pdes','$pdeliv','$cDate','$date','$pss',$ps)";
mysqli_query($link, $insertQ) or die(mysqli_connect_error($link));
$getPID = "SELECT * FROM project WHERE project_title = $pt AND project_description = $pdes AND project_deliverables = $pdel AND project_start = $cDate AND projecct_end = $date AND project_skillset = $pss";
$pid = mysqli_query($link, $getPID) or die(mysqli_connect_error($link));
if (mysqli_num_rows($pid) == 1) {
while ($row = mysqli_fetch_array($pid)) {
$proid = $row['project_id'];
$insertF = "INSERT INTO user_has_project(user_id,project_id) VALUES ('" . $uid . "','" . $proid . "')";
mysqli_query($link,$insertF) or die(mysqli_connect_error($link));
$message = "<p>Project Successfully Added!</p>";
$message .= "<a href='index.php'>Back</a>";
$a = true;
}
} else {
$message = "<p>Project Failed To Be Added!</p>";
$message .= "<a href='createProject.php'>Back</a>";
$a = false;
}
} else {
$message = "<p>Duplicate Project Found!</p>";
$message .= "<a href='createProject.php'>Back</a>";
$a = false;
}
} else {
$message = "<p>Please Fill Up All Fields When Creating A Project!</p>";
$message .= "<a href='createProject.php'>Back</a>";
$a = false;
}
//表单上的代码
<div id="content">
<?php if ($a == false) {
?>
<h2 id="registerFont">Create Project</h2>
<form name="createProject" method="post" action="doCreateProject.php" onSubmit="return validateForm(this);">
<fieldset>
<table>
<tr>
<th colspan="4"><h2>New Project</h2></th>
</tr>
<tr>
<th colspan="4"><hr /></th>
</tr>
<tr>
<td><label for="projectTitle">Project Title:</label></td><td><input name="projectTitle" type="text" /></td>
<td><label for="projectStatus">Project Status:</label></td>
<td><select name="projectStatus">
<?php while ($row = mysqli_fetch_array($result1)) {
?>
<option value="<?php echo $row['status_id']; ?>" ><?php echo $row['status_type']; ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td><label for="projectDesc">Project Description:</label></td><th colspan="3"><textarea name="projectDesc" rows="5" cols="40" ></textarea></th>
</tr>
<tr>
<td><label for="projectDeliv">Project Deliverables:</label></td><th colspan="3"><textarea name="projectDeliv" rows="5" cols="40" ></textarea></th>
</tr>
<tr>
<td>Start Date:</td><td><?php echo $date; ?></td>
</tr>
<tr>
<td>End Date : </td>
<th colspan="3" align="left">
<select name="year">
<option>---Year---</option>
<?php for ($i = $cYear; $i < ($cYear + 100); $i++) {
?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php } ?>
</select>
<select name="month">
<option>---Month---</option>
<?php while ($rows = mysqli_fetch_array($result)) {
?>
<option value="<?php echo $rows['month_id']; ?>"><?php echo $rows['month']; ?></option>
<?php } ?>
</select>
<select name="day">
<option>---Day---</option>
<?php for ($i = 1; $i < 32; $i++) {
?>
<option value="<?php echo $i ?>"><?php echo $i ?></option>
<?php } ?>
</select>
</th>
</tr>
<tr>
<td><label for="projectSS">Project Skill Set:</label></td><td><input name="projectSS" type="text"/></td><th colspan="2"><small>(Please Separate By Comma)</small></th>
</tr>
</table>
</fieldset>
<br />
<input name="submit" type="submit" value="Create Project" />
</form>
<?php
} else {
echo $message;
}
?>
</div>
答案 0 :(得分:0)
我设法解决了这个问题。在查询数据库时,在我的SELECT语句中,我忘记添加变量''。例如SELECT * FROM project WHERE project_title ='$ variable';
反正。谢谢那些帮忙的人。我真的很感激。