php中insert语句返回值,php – mysql_insert_id();成功插入行后不返回值

我发誓,我已倾倒并倾倒在本网站上的所有其他类似问题和其他人……但我想我只是遗漏了一些东西.希望有人可以指出一个愚蠢的错误,我的大脑正在躲避我. 🙂

我的脚本将表单中的值插入名为“notes”的表中

此时,它通过名为newRelationship的函数在名为“relationships”的表中创建两个条目.

变量“$note_id”的值通过我的mysql_insert_id()填充;并传入上述功能.

执行代码时,条目成功添加到“notes”,“id”列使用auto_increment赋予适当的值.

接下来,将两个条目添加到“关系”表中(正如它们所应).

但是,我的mysql_insert_id()继续踢出值“0”而不是新的行id.

对于我的生活,我无法弄清楚我做错了什么.我甚至尝试从头开始创建一个具有相同结果的新表.踢球者是我在项目的其他文件中使用几乎完全相同的代码而没有任何问题.有谁看到我做错了什么?

有问题的代码

if ($user->is_loaded())

{

if($_POST['project_id']) {

$project_id = $_post['project_id'];

$long_note = $_POST['long_note'];

$created_by = $_POST['created_by'];

$note_sql="INSERT INTO notes (`long_note`, `added`, `created_by`) VALUES ('$long_note', '$timenow', '$created_by')";

if (!mysql_query($note_sql,$con))

{

die('Error: ' . mysql_error($note_sql));

}

else {

echo "note created Creating relationship ";

$note_id = mysql_insert_id();

echo $note_id;

newRelationship($project_id, "project", $note_id, "note");

newRelationship($client_id, "client", $note_id, "note");

echo "note added successfuly";

}

而我的功能

function newRelationship($parent_id, $parent_type, $child_id, $child_type)

{

global $sql, $con, $timenow;

$relationship_sql="INSERT INTO `relationships` (`parent_id`, `parent_type`, `child_id`, `child_type`) VALUES ('$parent_id', '$parent_type', '$child_id', '$child_type');";

if (!mysql_query($relationship_sql,$con))

{

die('Error: ' . mysql_error($relationship_sql));

}

else {

echo $parent_type." ".$parent_id." realationship with ".$child_type." ".$child_id." successful ";

}

}

Per @ jack的建议是我的笔记表的sql

CREATE TABLE `notes` (

`id` int(10) unsigned zerofill NOT NULL AUTO_INCREMENT,

`contact_id` int(10) NOT NULL,

`client_id` int(10) NOT NULL,

`status` text NOT NULL,

`long_note` text NOT NULL,

`added` int(11) NOT NULL,

`modified` int(11) NOT NULL,

`edit_by` int(10) NOT NULL,

`short_note` text NOT NULL,

`created_by` int(10) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=MyISAM AUTO_INCREMENT=295 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值