PHP Web Host - Quality Web Hosting For All PHP Applications $35/month $250/year (Unlimited) - $25/month - 200,000 impressions - Your Ad Could be Here - Click For Details
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
Donovan
Client


Joined: Oct 07, 2003
Posts: 675
Location: Ohio

PostPosted: Fri Aug 31, 2007 12:34 pm Reply with quote Back to top

Another thread for help on my next issue for this standalone (Non Nuke) program.

As I stated on my other thread I have a single index.php page.

I have this at the top.

Code:
switch ($op) {


    case "comment":
    comment();
    break;
   
    case "reply":
    reply($cid);
    break;
   
   case "previewComment":
   previewcomment();
   break;
   
   case "submitComment":
   submitComment($title, $comment_text, $topic, $ipaddress);
   break;   
      
   default:
    index();
    break;
}


My form action for each function is:
Code:
action=\"" .$_SERVER['PHP_SELF']


In my comment function I have all my variables between my form tags such as

<select name=\"topic\">
<input type="\text\" name="\title\">
<textarea cols=\"50\" rows=\"12\" name=\"comment_text\"></textarea>

I send this to my submitComment function

Code:
echo'</p><p><input type="submit" name="submit" value="Submit" />&nbsp;&nbsp;'                          
         .'<input name="op" type="hidden" value="submitComment" />';   


Where I receive nothing when I try to just echo the variables.

Code:
function submitComment($title, $comment_text, $topic, $ipaddress) {

Opentable();
   echo"<tr><td>$title</td></tr></br >";
   echo"<tr><td>$comment_text</td></tr></br >";
   echo"<tr><td>$topic</td></tr></br >";
   echo"<tr><td>$ipaddress</td></tr></br >";
Closetable();

}


Any help is appreciated.
View user's profile Send private message Visit poster's website ICQ Number
Gremmie
Moderator


Joined: Apr 06, 2006
Posts: 2356
Location: Iowa, USA

PostPosted: Fri Aug 31, 2007 3:10 pm Reply with quote Back to top

Remember, register_globals is not on. You need to get the data out of the $_POST or $_GET arrays yourself.
View user's profile Send private message
Donovan
Client


Joined: Oct 07, 2003
Posts: 675
Location: Ohio

PostPosted: Fri Aug 31, 2007 3:19 pm Reply with quote Back to top

So within my comment function I would need to do something like:

$topic = $_Post['topic'];
View user's profile Send private message Visit poster's website ICQ Number
Gremmie
Moderator


Joined: Apr 06, 2006
Posts: 2356
Location: Iowa, USA

PostPosted: Fri Aug 31, 2007 3:36 pm Reply with quote Back to top

Yes, or wherever you want to use it.
View user's profile Send private message
fkelly
Moderator


Joined: Aug 30, 2005
Posts: 2056
Location: near Albany NY

PostPosted: Fri Aug 31, 2007 7:00 pm Reply with quote Back to top

I'm not positive but I think it has to be $_POST. Capitalized. You might also want to make it a habit to do an isset check on POST variables. Text type fields will always be passed in the POST array but checkboxes will not unless they are checked.
View user's profile Send private message Visit poster's website
montego
Site Admin


Joined: Aug 29, 2004
Posts: 7236
Location: Arizona

PostPosted: Sat Sep 01, 2007 6:55 am Reply with quote Back to top

Yes, it must be ALL CAPS. PHP is case sensitive on variable names.
View user's profile Send private message Visit poster's website
Donovan
Client


Joined: Oct 07, 2003
Posts: 675
Location: Ohio

PostPosted: Tue Sep 04, 2007 1:13 pm Reply with quote Back to top

How could I pass the $op variable from an admin menu that is called before each function.

Such as:

Code:
function admin_menu(){
 
  OpenTable(); 
  echo "<table border='1' align='center' width='100%' cellpadding='2' cellspacing='0'>\n";
  echo "<tr>\n";
  echo "<td align='center' valign='top' width='15%'>&nbsp;<b><u>Waiting Questions</u></b>&nbsp;</td>\n"; 
  echo "<td align='center' valign='top' width='15%'>&nbsp;<b><u>Change Your Info</u></b>&nbsp;</td>\n"; 
  echo "<td align='center' valign='top' width='15%'>&nbsp;<b><u>Courses</u></b>&nbsp;</td>\n";
  echo "</tr>\n";
  echo "<tr>\n";
  echo "<td align='center' valign='top' width='15%' rowspan='3'>\n"; 
  echo "&nbsp;<a href='index.php?op=listQuestions'>List Questions</a>&nbsp;<br />\n"; 
  echo "</td>\n"; 
  echo "<td align='center' valign='top' width='15%' rowspan='3'>\n"; 
  echo "&nbsp;<a href='index.php?op=info'>Your Info</a>&nbsp;<br />\n";   
  echo "</td>\n"; 
  echo "<td align='center' valign='top' width='15%' rowspan='3'>";   
  echo "&nbsp;<a href='index.php?op=listCourses'>List Courses</a>&nbsp;<br />";
  echo "</td>\n"; 
  echo "</tr>\n";
  echo "</table>\n";   
  echo "<table border='1' align='center' width='100%' cellpadding='2' cellspacing='0'>\n"; 
   CloseTable();
  }


If I click on List Questions it does not go anywhere but just refreshes. The $op is not being passed to the switch $op I have at the bottom of my index page.


Code:
$op = isset($_POST['op']) ? $_POST['op'] : '';
switch ($op) {


   case "listQuestions":
    listQuestions();
    break;

   case "info":
    info();
    break;

   case "listCourses":
    listCourses();
    break;   
   
   default:
    admin_menu();
    break;
}


globals are off and I can't seem get this concept thru my thick head that I need to $_POST the $op variable, but I don't know where.
View user's profile Send private message Visit poster's website ICQ Number
evaders99
Moderator


Joined: Apr 30, 2004
Posts: 2749

PostPosted: Tue Sep 04, 2007 4:38 pm Reply with quote Back to top

You can add the $op variable as a parameter or use it as a global

Code:

function admin_menu($op){

...

admin_menu($op);


or

Code:

function admin_menu(){
   global $op;
View user's profile Send private message Visit poster's website
montego
Site Admin


Joined: Aug 29, 2004
Posts: 7236
Location: Arizona

PostPosted: Wed Sep 05, 2007 5:13 am Reply with quote Back to top

Donovan, the links that you are showing within your function admin_menu() are not coming from a form with a method of POST. Therefore, in this case, these are in $_GET....
View user's profile Send private message Visit poster's website
Donovan
Client


Joined: Oct 07, 2003
Posts: 675
Location: Ohio

PostPosted: Wed Sep 05, 2007 6:31 am Reply with quote Back to top

Thanks Montego,

I didn't know coding with registered globals on made things much easier to a novice PHP developer. Without them it has lead to a bunch of errors in my code. Alas, things are more secure with them off, but it takes some getting used to.
View user's profile Send private message Visit poster's website ICQ Number
fkelly
Moderator


Joined: Aug 30, 2005
Posts: 2056
Location: near Albany NY

PostPosted: Wed Sep 05, 2007 7:35 am Reply with quote Back to top

Donovan, working without register globals is really not complicated. You either have $_POST variables or $_GET. These are all contained in a POST or GET array. If you are using a form with a POST request method then the field names on the form are all POSTED automatically to the receiving or processing program. You will want to validate them on the receiving end. There is an extensive discussion of this here:

Only registered users can see links on this board!
Get registered or login to the forums!


There is code in mainfile that turns register globals on (or I should say imports the variables) but I think there is general agreement that we would like to gradually convert Nuke so that we explicitly filter all variables rather than relying on implicitly importing them. That's going to take some doing since the old method permeates the core PHPnuke code. But for your new stuff you'd be better off getting familiar with the preferred approach. That's my opinion anyway.
View user's profile Send private message Visit poster's website
Donovan
Client


Joined: Oct 07, 2003
Posts: 675
Location: Ohio

PostPosted: Wed Sep 05, 2007 8:05 am Reply with quote Back to top

fkelly wrote:
Donovan, working without register globals is really not complicated. You either have $_POST variables or $_GET. These are all contained in a POST or GET array.


But if my admin_menu () did not have any form tags at all then the only way to find the value of $op was to $_GET?

Correct?

I changed this

Code:
$op = isset($_GET['op']) ? $_GET['op'] : '';
switch ($op) {

blah
blah
}



and now I am able to get inside my listQuestions() function.
View user's profile Send private message Visit poster's website ICQ Number
fkelly
Moderator


Joined: Aug 30, 2005
Posts: 2056
Location: near Albany NY

PostPosted: Wed Sep 05, 2007 8:12 am Reply with quote Back to top

Correct. You are either using the GET method or the POST one and in this case you are using GET. The important part is to conceptualize of user input (whether it be a form with POSTS or a selection that results in setting a GET) and the processing of that input as being a single integrated piece of code. Because of the nature of web architecture you can't total rely upon the fact that anything sent to your processing program comes from the source it says it comes from so you need to filter to assure that only legitimate variables (POSTS or GETS) are received and acted on.
View user's profile Send private message Visit poster's website
Donovan
Client


Joined: Oct 07, 2003
Posts: 675
Location: Ohio

PostPosted: Tue Sep 11, 2007 11:50 am Reply with quote Back to top

Well I'm still having trouble here.

I can list the questions and can choose which question I want to edit. Within the edit question function I have a textarea where the text is located but when I try and post that to a saveQuestion function all I am getting is the $cid of that question. I cannot pass the text or title of that question.

For example:

//list questions
Code:
OpenTable();   
   echo "<table width=\"100%\" border=\"0\">";   
   echo "<tr>";   
   echo "<td align=\"left\" width=\"50%\"><div class=\"content\">$title</div></td>";   
   echo "<td align=\"center\" width=\"25%\"><div class=\"content\">$formatdate</div></td>";
   echo "<td align=\"right\" width=\"25%\"><div class=\"content\"><a href=\"index.php?op=editQuestion&cid=$cid\">Edit</a></div></td>";
   echo "</tr>";         
   echo "<input name=\"cid\" type=\"hidden\" value=\"$cid\" />";   
   echo "</form>";   
   echo "</table>";   
   CloseTable();   


Edit Questions since $cid is not declared in listQuestion or outside any form tags I have to $_GET

Code:

function editQuestion() {
global $AllowableHTML, $db;
$cid = $_GET['cid'];

$result = $db->sql_query("SELECT * FROM comment_queue WHERE cid = '$cid'");
while ($row = $db->sql_fetchrow($result)) {

   $title = stripslashes(check_html($row['title'], 'nohtml'));
   $comment_text = stripslashes(check_html($row['comment_text'], 'nohtml'));
   }     
   
    OpenTable();                
    echo "<b>Title:</b><br />"
        ."<input type=\"text\" name=\"title\" size=\"50\" maxlength=\"80\" value=\"$title\" /><br />";   
    echo "<b>Text:</b>You can use HTML to format your question.<br />"
        ."<textarea cols=\"50\" rows=\"15\" style=\"background:#EFEFEF\" name=\"comment_text\">$comment_text</textarea><br />";   
    echo "<p>If you included any URLs or html, be sure to double check them for typos.</p>"
        ."<p>Allowed HTML:<br />"
        ."</p>"
      ."<p>";
    while (list($key,) = each($AllowableHTML)) echo ' &lt;'.$key.'&gt;';
    echo "</p>";   
   echo"<select name=\"op\">"
        ."<option value=\"deleteQuestion\">Delete Question</option>"
        ."<option value=\"preview\" selected=\"selected\">Preview</option>"
        ."<option value=\"postReply\">Post Reply</option>"
        ."</select>"
        ."<input type=\"submit\" value=\"OK\" />";      
      echo"<br>";
      echo"<a href=\"index.php?op=deleteQuestion&cid=$cid\">Delete</a>";
      echo"<br>";
      echo"<a href=\"index.php?op=previewQuestion&cid=$cid\">Preview</a>";
      echo"<br>";
      echo"<a href=\"index.php?op=saveQuestion&cid=$cid\">Save</a>";
      echo"<br>";            
    echo "</form>";
    CloseTable();   
}


^
^
My list box is not working so I am using links for now.

I need to send the contents of $comment_text and $title to the saveQuestion function to update those fields.


Code:
function saveQuestion() {
global $db;
$cid = $_GET['cid'];
$title = $_POST['title'];
$comment_text = $_POST['comment_text'];
echo"$cid";
echo"<br>";
echo"$title";
echo"<br>";
echo"$comment_text";


The only thing I am able to echo out is $cid

In the editQuestion function I am using the PHP_SELF as action but Sentinal wont let me use that.
View user's profile Send private message Visit poster's website ICQ Number
fkelly
Moderator


Joined: Aug 30, 2005
Posts: 2056
Location: near Albany NY

PostPosted: Tue Sep 11, 2007 1:39 pm Reply with quote Back to top

I don't see any form tag with a method="post". In fact I just see a closing form tag and not an open one. Am I missing it? You can't post anything if your method isn't post. Furthermore you don't have an action attribute.

I'd recommend that you go entirely with posts and forget the gets. You might have one form that posts the cid and another that retrieves it and sticks the question in a textarea and then posts any edits that are done on that. I'd also recommend that you run what you have (or any amended version) thru the w3c validator. It will point out any missing tags. I also haven't seen that "while (list($key,)" syntax before. That may just be my inexperience but that comma looks suspicious to me. What's it there for?
View user's profile Send private message Visit poster's website
Donovan
Client


Joined: Oct 07, 2003
Posts: 675
Location: Ohio

PostPosted: Tue Sep 11, 2007 1:53 pm Reply with quote Back to top

All my forms start with method post and action .$_SERVER['PHP_SELF']



But NukeSentinal was choking on this so I left it out of the post.

The , is to separate the Allowable html "keys" in an array.

Code:
$AllowableHTML = array(
    'a' => array('href' => 1, 'target' => 1, 'title' => array('minlen' => 4, 'maxlen' => 120)),
    'b' => array(),
    'blockquote' => array(),
    'br' => array(),
    'center' => array(),
    'div' => array('align' => 1),
    'em' => array(),
    'font' => array('face' => 1, 'style' => 1, 'color' => 1, 'size' => array('minval' => 1, 'maxval' => 7)),
    'h1'=>array(),
    'h2'=>array(),
    'h3'=>array(),
    'h4'=>array(),
    'h5'=>array(),
    'h6'=>array(),
    'hr' => array(),
    'i' => array(),
    'img' => array('alt' => 1, 'src' => 1, 'hspace' => 1, 'vspace' => 1, 'width' => 1, 'height' => 1, 'border' => 1, 'align' => 1),
    'li' => array(),
    'ol' => array(),
    'p' => array('align' => 1),
    'pre' => array('align' => 1),
    'span' =>array('class' => 1, 'style' => array('font-family' => 1, 'color' => 1)),
    'strong' => array(),
    'strike'=>array(),
    'sub'=>array(),
    'sup'=>array(),
    'table' => array('align' => 1, 'border' => 1, 'cell' => 1, 'width' => 1, 'cellspacing' => 1, 'cellpadding' => 1),
    'td' => array('align' => 1, 'width' => 1, 'valign' => 1, 'height' => 1, 'rowspan' => 1, 'colspan' => 1 ),
    'tr' => array('align' => 1),
    'tt'=>array(),
    'u' => array(),
    'ul' => array(),
);


I was trying at one time to use fckeditor but never got it working. Maybe in version 2 of this project.
View user's profile Send private message Visit poster's website ICQ Number
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2008 by Raven
Proud to be listed at Lobo Links Web Directory

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::

:: fisubice Theme Recoded To 100% W3C CSS & HTML 4.01 Transitional Compliance by Raven and 64bitguy ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum