razorsese Posted April 2, 2012 Share Posted April 2, 2012 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 More sharing options...
dragon_sa Posted April 2, 2012 Share Posted April 2, 2012 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 https://forums.phpfreaks.com/topic/260174-php-variable-passing-in-multiple-page/#findComment-1333467 Share on other sites More sharing options...
razorsese Posted April 2, 2012 Author Share Posted April 2, 2012 Tried that but now the problem appear before i submit something right on viewArticle.php page Link to comment https://forums.phpfreaks.com/topic/260174-php-variable-passing-in-multiple-page/#findComment-1333472 Share on other sites More sharing options...
dragon_sa Posted April 2, 2012 Share Posted April 2, 2012 this is also missing the semi colon <h1> <?php echo $result['article']->text ?> </h1> should be <h1> <?php echo $result['article']->text; ?> </h1> Link to comment https://forums.phpfreaks.com/topic/260174-php-variable-passing-in-multiple-page/#findComment-1333477 Share on other sites More sharing options...
razorsese Posted April 2, 2012 Author Share Posted April 2, 2012 Well I fixed it by pass in function addcomment($pass) a variable Link to comment https://forums.phpfreaks.com/topic/260174-php-variable-passing-in-multiple-page/#findComment-1333480 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.