我有一个包含以下php代码的页面:
<?php
include ('databaseconnect1.php');
$sql1= "SELECT Categoryid, Categoryname, Categorydescription
FROM Categories";
$result1 = mysqli_query($db,$sql1);
if (!$result1){
echo "<font color = 'Green' .<p> No Category Found, Contact the
administrator </p> </font>";
}
function getPosts()
{
$posts = array();
$posts[0] = $_POST['topic_subject'];
$posts[1] = $_POST['date'];
$posts[2] = $_POST['topic_category'];
$posts[3] = $_SESSION['userid'];
return $posts;
}
if (isset($_POST['createtopicbutton']))
{
$data = getPosts();
$sql2 = "INSERT INTO Topics(Topic_subject, Topic_date,
Topic_category, Topic_by)
VALUES('$data[0]','$data[1]', '$data[2]', '$data[3]')";
$result2 = mysqli_query($db,$sql2);
if ($result2){
echo "<font color = 'Green' .<p> Topic Successfully Created </p>
</font>";
}else{
echo "<font color = 'Green' .<p> Topic NOT! Successfully Created </p>
</font>"; //This is the result I am getting specifically
}
}
?>
这是同一页面上的HTML代码:
<form method = "post" action = "" >
<table cellspacing="15">
<tr>
<th>Subject </th>
<td><input type = "text" name = "topic_subject" /> </td>
</tr>
<tr>
<th>Category </th>
<?php echo '<td> <select name="topic_category"> ';
while($row = mysqli_fetch_assoc($result1))
{
echo '<option value="' . $row['Categoryid'] . '">' .
$row['Categoryname'] . '</option>';
}
echo '</select></td>';
?>
</tr>
<tr>
<th>Current Date </th>
<td><input type = "text" name = "date" /> </td>
</tr>
<tr>
<th> </th>
<td> <input type = "submit" value = "Create Topic!" name =
"createtopicbutton" /> </td>
</tr>
</table>
</form>
我需要帮助的具体部分是当按下“createtopicbutton”时,我只得到以下结果:
<?php Topic NOT! Successfully Created?>
以下是主题表的表格结构:Table Structure from phpmyadmin
这是整个数据库表结构的一部分:Linkages of tables
到目前为止,我已经尝试确保所有括号都已正确关闭,并且稍微改变语法并且没有成功。然而,唯一有效的是当我通过phpmyadmin输入数据时它会以某种方式工作。所以我觉得问题与表格有关。你能帮忙吗?
答案 0 :(得分:0)
integral2