我正在尝试从函数返回变量。我有下面的函数,它将一个postid插入数据库。我需要将postid的值返回到另一页。
forum.php-函数在哪里。
function newTopic(){
// Get the POST data
global $ir;
$postid = mysql_insert_id();
mysql_query("UPDATE forum_topics SET post_id='$postid' WHERE topic_id='$topicid'");
// No error found and the update was succesful - Return success!
return 100;
return $postid;
}
newtopic.php-我需要$postid
变量的地方。
if($_POST)
{
$newTopic = $forum->newTopic();
/*
* Return codes:
* 100: Success
*/
switch($newTopic)
{
//If no error = success.
case 100:
$success = 'You have successfully created the topic.';
$issuccess = 1;
$stop = true;
break;
}
$checkerror = $error;
$checksuccess = $success;
}
if($checksuccess){
$contents.="
".alert("success","$success")."";
refresh("3","/forum/t$id-$postid");
}
如您所见,我正在尝试使用newTopic()函数中的$ postid变量。虽然,$ postid变量为空。
如何从位于forum.php中的newTopic.php函数获取值到newtopic.php?
当您使用过
return 100;
您的代码将永远看不到
return $postid;
您可以使用此代码返回
return array("code"=>"100","postid"=>$postid);
现在在new_topic.php中使用如下所示的代码
if($_POST)
{
$newTopic = $forum->newTopic();
/*
* Return codes:
* 100: Success
*/
switch($newTopic['code'])
{
//If no error = success.
case 100:
$success = 'You have successfully created the topic.';
$issuccess = 1;
$stop = true;
break;
}
$checkerror = $error;
$checksuccess = $success;
}
if($checksuccess){
$contents.="
".alert("success","$success")."";
refresh("3","/forum/t$id-$newTopic['postid']");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句