我有一個論壇,用戶可以輸入他們正在尋找的工作,這將提交到數據庫,然後顯示在下一頁。只有我無法獲取任何數據才能上傳,我不知道爲什麼。作業資料不提交到數據庫表
我也在努力尋找錯誤檢查的方法。有任何想法嗎?
// Check for job submission
if(isset($_POST['submit']))
//empty error array
$error = array();
// check for a things in the field
if(empty($_POST['job']))
{
$error[] = 'Please fill in all required fields';
}
// iff there are no errors, insert the job listing into the database.
// otherwies, display error.
if(sizeof($error) == 0)
{
// insert job listing
$query = "INSERT INTO job (
job_id,
user_id,
jobtitle,
company,
location,
summary,
responsibilities,
skills
) VALUES (
null,
'{$_SESSION['user_id']}',
'{$_POST['jobtitle']}',
'{$_POST['company']}',
'{$_POST['location']}',
'{$_POST['summary']}',
'{$_POST['responsibilities']}',
'{$_POST['skills']}',
NOW()
)";
$result = mysqli_query($dbc, $query) or die('Query failed: ' . mysqli_error($dbc));
// display a confirmation
echo "<div class=\"alert alert success\">Your job listing has been added</div>";
} else {
// display error message
foreach($error as $value)
{
echo "<div class=\"alert alert-danger\"{$value}</div>";
}
}
?>
<!-- Job listing Form -->
<form method="post" action="listings.php">
<div class="form-group">
<label> Job Title </label>
<input name ="jobtitle" type="text" class="jobform"/>
<label>Company/Organization</label>
<input name="company" type="text" class="jobform"/>
<label> Job Location </label>
<input name ="location" type="text" class="jobform"/>
<label> Job Responsibilities </label>
<textarea name="summary" rows="8" cols="20" class="jobfourm"></textarea>
<label> Job Responsibilities </label>
<textarea name="responsibilities" rows="8" cols="20" class="jobfourm"></textarea>
<label> Job Skills </label>
<textarea name="skills" rows="8" cols="20" class="jobforum"></textarea>
</div>
<div class="form-group">
<input name="submit" type="submit" value="Submit" class="btn btn-large btn-primary" />
</div>
</form>
</div>
*旁註:*您的代碼受到SQL注入攻擊,因爲您直接允許將POST值插入到您的查詢中。 – Raptor
@ Raptor我知道,我有點還在學習它,所以爲了這個練習,我更加努力地在輸入代碼以防止注入之前弄清基本工作代碼 –
@ChristineAustin這是一個明智的方法,但它永遠不會早期提供良好的安全:) – Zarathuztra