这是代码:
<html>
<body>
<?php
$valid = true;
//Check for first name value
if (empty($_POST['texts'])) {
echo 'You forgot to type something in<br />';
$valid = false;
}
if ($valid == true) {
$conn1 = mysqli_connect('xxx') or die('Error connecting to MySQL server.');
$name= $_POST['name'];
$title= sha1($_POST['title']);
$texts= $_POST['texts'];
$forum_id = $_POST['forum_id'];
$name = str_replace("'","''",$name);
$title = str_replace("'","''",$title);
$title = str_replace("b074acd521","STREAMER",$title);
$texts = str_replace("'","''",$texts);
$title = substr($title,0,8);
$sql = "INSERT INTO post (name,title, texts, forum_id) VALUES ('$name', '$title', '$texts', '$forum_id')";
mysqli_query($conn1, $sql) or die('Error inserting to database.');
mysqli_close($conn1);
header('Location: requests.php');
}
else {
echo 'Click <a href="javascript:history.go(-1)">HERE</a> to go back and adjust your entry.';
}
?>
</body>
</html>
当我在网站上发帖并将 id 字段留空时,它仍然会生成一个 ID,我该如何解决这个问题?另外,如果名称字段为空,我怎样才能将其设为默认值?