gpt4 book ai didi

PHP MySQL不插入数据库

转载 作者:行者123 更新时间:2023-11-29 04:55:00 25 4
gpt4 key购买 nike

我听说过这个问题,但似乎无法弄清楚。我有正确的数据库和表名。我没有发现任何错误,我什至在 phpmyadmin 上插入了一个有效的表格,但是当我尝试在我的网站上这样做时,它不起作用。我什至测试了连接..不知道现在该做什么

也许有人可以看看我的代码,看看他们是否注意到了什么

<?php
if(mysql_connect('<db>', '<un>', '<pw>') && mysql_select_db('smiles'))
{

$time = time();
$errors = array();

if(isset($_POST['guestbook_name'], $_POST['guestbook_message'])){
$guestbook_name = mysql_real_escape_string(htmlentities($_POST['guestbook_name']));
$guestbook_message = mysql_real_escape_string(htmlentities($_POST['guestbook_message']));

if (empty($guestbook_name) || empty($guestbook_message)) {
$errors[] = 'All Fields are required.';
}
if (strlen($guestbook_name)>25 || strlen($guestbook_message)>255) {
$errors[] = 'One or more fields exceed the character limit.';
}
if (empty($errors)) {

$insert = "INSERT INTO 'guestbook'VALUES('','$time','$guestbook_name','$guestbook_message')";
if($insert = mysql_query($insert)){
header('Location: '.$_SERVER['PHP_SELF']);
} else{
$errors[] = 'Something went wrong . Please try again.';
}
} else {
foreach($errors as $error) {
echo '<p>'.$error.'</p>';
}
}

}
//display entries
}
else {
'Fixing idiot';
}
?>
<hr />
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="POST">
<p>Post Somethign</p>
<br />
Name:<br /><input type="text" name="guestbook_name" maxlength="25" />
<br />
Message:
<br />
<textarea name="guestbook_message" rows="6" coles="30"maxlength="255"></textarea>
<input type="submit" value="Post" />
</form>

最佳答案

从表名 'guestbook' 中删除引号,并在它和 values 之间留一个空格

关于PHP MySQL不插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7393951/

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