gpt4 book ai didi

php - 作业条目未提交到数据库表

转载 作者:行者123 更新时间:2023-11-29 13:22:50 25 4
gpt4 key购买 nike

我有一个论坛,用户可以在其中输入他们正在寻找的工作,该工作将提交到数据库,然后显示在下一页上。只是我无法上传任何数据,我也不知道为什么。

我也在努力寻找错误检查的方法。有什么想法吗?

// 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>

最佳答案

我的赌注是你的查询:

 (
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()

对于应为 job_id 的内容,您传递的是 null。现在,我假设所有作业都必须有一个作业 ID,对吗?您实际上需要传递一个有效的 id,因为我将用钱(或代表)打赌,那是表中不可为空的字段。此外,您在值中添加了一个未在列名称参数中声明的列。

关于php - 作业条目未提交到数据库表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20558122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com