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
https://forums.phpfreaks.com/topic/260174-php-variable-passing-in-multiple-page/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.