Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Donovan
Client



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

PostPosted: Wed Aug 29, 2007 8:07 am Reply with quote

I am working on a standalone anonymous question and answer system for work. These d*** students never seem to want to ask what they fear might be a stupid question in class, so this will allow them to submit anonymous questions to their course directors.

So far the structure is the following:

comment
comment/index.php
comment/header.php
comment/footer.php
comment/config.php
comment/includes/db.php
comment/includes/mysql.php
comment/includes/function.php
comment/language/lang-english.php

My index.php is where I will have most of my functions such as index(), reply(), comment() ..... etc.

The function.php is where I will do some check_html() stuff.

This is my first standalone application. My problem is my index.php page has the following that doesn't appear to be working at all.

Code:
switch($op) {


    case "comment":
    comment($cid);
    break;
   
    case "reply":
    reply($cid);
    break;
   
   default:
    index();
    break;
}


index() lists all the comments on the page and there is a reply button at the bottom that would I hope send me to the reply function such as:

Nukesentinal kept blocking me.

I am using SERVER PHP_SELF as form action.

Code:
         

   echo '<input name=\'submit\' type=\'Submit\' value=\'Reply\'>';
   echo '<input name=\'op\' type=\'hidden\' value=\'reply\'>';
   echo '<input name=\'op\' type=\'hidden\' value=\'$cid\'>';
   echo '</form>';   
   


The only thing that is happening is my index.php is refreshing.

And help is most appreciated. I am begining to realize how easy it was to create a module in Nuke rather than code a standalone application.
 
View user's profile Send private message Visit poster's website ICQ Number
fkelly
Former Moderator in Good Standing



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

PostPosted: Wed Aug 29, 2007 8:44 am Reply with quote

First, echo out the $op and verify what it is being set to.

Second, in your echoes for the forms you need to be doing it like this:

Code:
   echo '<input name="submit" type="'Submit"' value="Reply" />';


I'm not sure what would happen with the way you have it, I'd think you will get a single quote around submit and Submit and Reply. Also, I believe that the validator will have fits with the type having a capital letter in it. I'm not sure but I think so. You also need the closing / in the inputs to pass validation.

Try that and see what happens.
 
View user's profile Send private message Visit poster's website
Donovan







PostPosted: Wed Aug 29, 2007 9:54 am Reply with quote

I made it look like this.


Code:
echo '<input name="submit" type="submit" value="Reply" />';   


I would rather have funtions in my index.php and use this switch with case statements, but I just don't think it is going to work.

I was thinking of using

Code:
if ($op == "reply") { 
 
Gremmie
Former Moderator in Good Standing



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

PostPosted: Wed Aug 29, 2007 10:55 am Reply with quote

If this is a stand alone app and not nuke, you may not have register_globals on (which is a good thing). You didn't say how you obtained the value of $op. Here is one way to do it:

Code:


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


Recall that under Nuke, register_globals is on, so all the variables from $_GET, $_POST, etc magically appear as global variables. With that off, you'll have to retrieve them yourself.

_________________
GCalendar - An Event Calendar for PHP-Nuke
Member_Map - A Google Maps Nuke Module 
View user's profile Send private message
Donovan







PostPosted: Wed Aug 29, 2007 11:24 am Reply with quote

Gremmie wrote:
If this is a stand alone app and not nuke, you may not have register_globals on (which is a good thing). You didn't say how you obtained the value of $op. Here is one way to do it:

Code:


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


Recall that under Nuke, register_globals is on, so all the variables from $_GET, $_POST, etc magically appear as global variables. With that off, you'll have to retrieve them yourself.


registered_globals are indeed off. So I should be doing something like:

Code:
$op = $_GET["op"]; 


within all my functions? Do I need to do this in each of my functions?
 
fkelly







PostPosted: Wed Aug 29, 2007 11:34 am Reply with quote

You should not need $op in all your functions. $op should just control which functions get called. If the form has a method="post" then you will have to do $_POST['op'] (note single quotes) as Gremmie suggested. Gremmie also suggested an isset test. You may want this in conjunction with a diagnostic echo of 'op = ' . $op to display the value. Then when you have the value being reliably sent over from your form you can get rid of the diagnostic echo. If you want the value of $op within your functions you can probably get it with a global statement. But I don't know why you would, it is usually a driver of what functions get called. The whole admin.php structure of Nuke is driven by a complex series of ops so there are plenty of examples.
 
Donovan







PostPosted: Wed Aug 29, 2007 12:12 pm Reply with quote

fkelly wrote:
If the form has a method="post" then you will have to do $_POST['op'] (note single quotes) as Gremmie suggested. Gremmie also suggested an isset test. You may want this in conjunction with a diagnostic echo of 'op = ' . $op to display the value. Then when you have the value being reliably sent over from your form you can get rid of the diagnostic echo.


Thanks for your help.

The form does use "post" so I am trying to use $_POST['op'] along with Gremmie's isset test.

The echo of $op is itself, as if a string value.

My case statement now looks like this:

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

switch ($op) {


    case 'comment':
    comment($cid);
    break;
   
    case 'reply':
    reply($cid);
    break;
   
    default:
    index();
    break;
}



The page is defaulting to index() no matter what which tells me no value is getting set for $op.

This in my index() is not setting the value.

Code:
echo '<input name="submit" type="submit" value="Reply" />';

echo '<input name=\'op\' type=\'hidden\' value=\'reply\'>';
 
fkelly







PostPosted: Wed Aug 29, 2007 3:53 pm Reply with quote

Ummm ... I'm not sure but try double quotes around the case "comment". Instead of single quotes around comment if that's clear.

Problem is that single quotes will interpret whatever is within there literally. Double quotes means it will be interpreted. If I am not mistaken the case statement is looking for the meaning of the special variable op. With the single quotes it may not be interpreting op. I think. Easy enough to try anyway. Let us know

Oh .. ut oh. I am looking at your code before posting this. You need to do the same thing with the line where the input name is op as you did for the one with submit. In other words input name="op" type="hidden" value=reply and then the closing / preceded by a space before the closing >. In my previous example I was assuming you would carry this thru to the other lines. If you don't understand take a look at view source the way you have it. The W3c standards require the value of an attribute to be enclosed in double quotes and \' is not going to do that.
 
montego
Site Admin



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

PostPosted: Wed Aug 29, 2007 8:23 pm Reply with quote

Actually, attributes just have to be quoted with matching quote types. So, on one, you could use "" and another '', but, of course, it is cleaner it you just standardize and if you always use double quotes on the attributes, you don't have to escape the single quotes like you have... its just cleaner.

The real question is are you sure this is coming in on the $_POST and not the $_GET? I don't see your form method, so I am not sure. Those have to match up... Wink

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
Donovan







PostPosted: Fri Aug 31, 2007 8:47 am Reply with quote

Been hammering on this for a bit.

I think the problem is this is a standalone project and I don't think the $_SERVER['PHP_SELF'] in the form action is doing what I need.
 
Donovan







PostPosted: Fri Aug 31, 2007 8:49 am Reply with quote

I am tired of posting code that is blocked by NukeSentinal and I don't have time to edit and try and repaste.
 
montego







PostPosted: Sat Sep 01, 2007 6:19 am Reply with quote

You could just copy it into a .txt file and make it accessible somewhere through a link for us. At least while we are debugging.

Up to you of course.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

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
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©