Jump to content

PHP variable passing in multiple page


razorsese

Recommended Posts

So i got the following problem:

 

i got some pages : index.php , comment.php, viewArticle.php

 

When i try to submit something from comment.php appear a error "Undefined variable:result"

The var result is defined in index.php

When i click on one article from the list the function viewArticle() is requiring viewArticle.php and the function addcomment() is requiring comment.php

 

The addcomment function() is in viewArticle function()

 

I can't figure out what's wrong but I guess have something to do whit the form action="index.php?action=viewArticle&articleid=<?php echo $result['article']->id?>"

 

index.php code

<?php

include('config.php');

$action = isset($_GET['action'])?$_GET['action']:"";

switch($action)
{
case 'viewArticle':viewArticle();break;
    default:homepage();
}

function homepage()
{
$result = array();
    $data = Article::getlist(1);
    $result['article']=$data['result'];
$result['total']=$data['totalrows'];
    require('homepage.php');	
}

function viewArticle()
{
if( !isset($_GET['articleid']) )homepage();
$result = array();
    $result['article'] =  Article::getbyid((int)$_GET['articleid']);
$result['name'] = $result['article']->name;
addcomment();
require('viewArticle.php');
}

function addcomment()
{

   
if(isset ($_POST['submit'] ))
{
$comment = new Comment;
$set = array();
$set['usern']="HJhj";
$set['com']="aca wqeq";
$set['page']=7;
$comment->storeFormValues($set);
$comment->insertc();
}
    else require('comment.php');

}

?>

 

viewArticle.php code

<center>
<h1> <?php echo $result['article']->text ?> </h1>

 

comment.php code:

 

<form method='post' action="index.php?action=viewArticle&articleid=<?php echo $result['article']->id?>" >
<input type="hidden" name="id" value="56"/>

<ul>
<li>
  <input type="text" name="usern" id="usern" />
</li>

<li>
<textarea name="com" id="com" COLS=40 ROWS=6></textarea>
</li>

<input type="hidden" name="page" value="56" />
<input type="submit" name="submit" value="submit" />

</form>

Link to comment
Share on other sites

you are missing a semi colon here

 

<form method='post' action="index.php?action=viewArticle&articleid=<?php echo $result['article']->id?>" >

 

should be

<form method='post' action="index.php?action=viewArticle&articleid=<?php echo $result['article']->id; ?>" >

 

also check your html output to make sure the variable id you want is actually displaying

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.