//require_once("../StoredProcedure/connect.php");
$conn=mysql_connect("localhost","root","") or die(mysql_error);
mysql_select_db("politicalforum",$conn);
function updateThread($threadID, $content)
{
mysql_query("UPDATE threads
SET content='$content'
WHERE thread_id=$threadID") ;
// $res = mysql_query($sql) or trigger_error(mysql_error().$sql);
mysql_close();
}我明白了每个time..what我做错了吗?
没有选择数据库。
我从一个外部的file...like调用这个函数。
if(isset($_GET['threadID']) && isset($_POST["reply"]) && isset($_POST['textareas']))
{
updateThread($_GET['threadID'], $_POST['textareas']);
$postValid=TRUE;
}发布于 2011-10-23 16:49:59
您的连接可能超出范围,导致mysql_query针对上下文的数据库对象运行,而在updateThread触发时该对象并不存在。
在这种情况下,您需要将连接传递到mysql_query函数中的updateThread中。在建筑上,有两种方法可以做到这一点:
1)打开并关闭updateThread函数中的连接:
function updateThread($threadID, $content)
{
$conn=mysql_connect("localhost","root","") or die(mysql_error);
mysql_select_db("politicalforum",$conn);
mysql_query("UPDATE threads
SET content='$content'
WHERE thread_id=$threadID", $conn) ;
mysql_close($conn);
$conn = null;
}2)将连接作为变量传递给updateThread,以便在其他函数中使用相同的连接。当脚本完成时,PHP将自动关闭并释放MySQL连接:
function updateThread($threadID, $content, $conn)
{
mysql_query("UPDATE threads
SET content='$content'
WHERE thread_id=$threadID", $conn) ;
}https://stackoverflow.com/questions/7867545
复制相似问题