php - 无法向数据库插入新行

标签 php jquery mysql

这是我的 php:

<?php
require included.php; //which contains the function getpost($post_id)
//once I use the getpost() function below to return a string which is the post 
//content, then I can not insert this new row to database.if I change it something 
//like $post_content='this is the post content' , it would insert a row to database

$post_content=getpost($post_id);
if($insert=mysql_query("INSERT INTO `join` VALUES('','username','$post_content')"))
{
   echo 'ok';
}
else{

   echo 'error';
}
?>

这里是included.php中的函数getpost($post_id):

function getpost($post_id){

    $select_post=mysql_query("SELECT `post_text` FROM `user_post` WHERE `id`='$post_id' ");
return mysql_result($select_post,0,'post_text');
}

这些数据将作为数据发送回 jquery AJAX 请求,如果我回显 $post_content = get_post($post_id),我可以提醒正确的内容,使用起来似乎有问题获取帖子内容的函数,然后无法将其插入数据库。

最佳答案

打字错误 -

...INSERT INTO `join` VALUERS('','usern...
                           ^

关于php - 无法向数据库插入新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21646875/

相关文章:

php 从 mySQL 数据库中检索数据到表单中

jquery - 在 Mocha 测试中使用 jQuery,使用 Node 而不是 io.js

javascript - 如何垂直使用 Owl Carousel ?

mysql连接在控制台关闭时自动关闭

PHP - 如何在带双引号的文本字段中传递变量

php - php 中的短唯一标识

Php,请求时锁定数据库?

javascript - 检索本身包含变量的 Jquery 变量名的值

php - 在 PHP 中分割 Mysql 列数据

php - Yii2 yii\helpers\Url helpers 到另一个站点的 Url