我有一个PHP脚本,假设从html表单获取值并将它们插入PDO数据库我确实设置了表。 它不会给出错误或工作。
这是HTML"表格"代码:
<form action="latestarticles.php" method="POST">
<input type="text" name="title" value="Title"/>
<input type="text" name="author" value="Author name"/>
<textarea name="content"></textarea>
<input type="datetime-local" name="currentdate" />
<select name="category">
<option value="Sports">Sports</option>
<option value="Local news">Local news</option>
<option value="Technology">Technology</option>
<option value="Business">Business</option>
</select>
<input type="reset" name="reset" value="Reset" />
<input type="submit" name="submit" value="submit" />
</form>
这是php代码 latestarticles.php :
<?php
if (isset($_POST['submit'])) {
$stmt = $pdo->prepare("INSERT INTO articles (articletitle, articleauthor, articlecontent) VALUES ($_POST['title'], $_POST['author'], $_POST['content'])");
$stmt->execute();
echo '<p> Successful insert </p>';
} else {
echo '<p> You suck at programming </p>';
}
?>
感谢您的帮助!