朱元璋扮演者:关于mysql向数据库插入一条记录的问题

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 19:03:48
我的程序如下:
<?php
$parent = $_POST['parentId'];
$name = $_POST["newone"];

$connection = mysql_connect('localhost', 'name', 'pw');
mysql_query('SET CHARACTER SET utf8');
$get_priority = mysql_query("select max(priority) from mydb where parent = $parent");
// echo "select max(priority) from mydb where parent = $parent;";
$priority = mysql_result($get_priority, 0, 0) + 1;
$get_parentName = mysql_query("select name from mydb where id = $parent");
// echo "select name from mydb where id = $parent;";
$parentName = mysql_result($get_parentName, 0, 0);
$label = "$parentName-$name";

mysql_query("insert into mydb (parent, name, priority, label) values($parent,'$name', $priority,'$label')");

mysql_close($connection);
?>
但运行时显示:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in D:\Program Files\xampp\htdocs\Category\functions\add.php on line 9

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in D:\Program Files\xampp\htdocs\Category\functions\add.php on line 12
无法在数据库中加入文件 求各位大虾帮助 小弟新人 这里先谢过了
问题解决了:)
再加上mysql_select_db('tattertools', $connection) or die ('Can\'t use : ' . mysql_error()); 就好了 :)

mysql_result($get_priority, 0, 0) 这个函数的参数有问题吧
你看看php的参考手册