Board index   FAQ   Search  
Register  Login
Board index PHP PHP Installation

I can't run my functions on .php pages

Forum for you who has PHP installation issues

Moderators: macek, egami, gesf

I can't run my functions on .php pages

Postby Board_Talk » Mon May 03, 2004 7:28 am

I am having issues with trying to get functions to work correctly on my localhost for php. I know the php works because the initial call to load my index.php comes up fine, however, when I click a link like the one shown below, it simply reloads the page to the initial default function.

This is the link I would like to call.
localhost/Folder/code.php?act=view&PkId=1

This is my switch function:
switch($act) {
case "selection":
view_Selection();
break;

default:
view_Index();
break;
}

?>

Is there a setting in the php.ini I need to set to run functions or have I done something else wrong? I know the code works great already as I have it installed on my webhosting service with no issues.

Thanks.
Last edited by Board_Talk on Tue May 04, 2004 7:22 am, edited 1 time in total.
Board_Talk
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon May 03, 2004 6:37 am

Postby gesf » Mon May 03, 2004 9:41 am

Board_Talk wrote:..when I click a link like the one shown below, it simply reloads the page to the initial default function.

In your link, the value of $act is 'view' and in your switch statement you have only one case... for 'selection'. Or, you don´t have nothing to verify that 'action'!
So... you can make: case "view":, otherwise it will always go to the default function...
User avatar
gesf
Moderator
Moderator
 
Posts: 1718
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby Board_Talk » Mon May 03, 2004 1:38 pm

please note: the code sample I gave above is a simple breakdown of the entire switch portion. Like I said tho, this whole project runs great already on my webhost. I am trying to set up a dev platform at my home. I am working on winxp pro with apache 1.3.29 and php 4.3.6

It just seems to completely bypass the switch and always go directly for the default. I have used echo statements to see if it even recognizes where it is while the script runs to no avail. It simply runs right for the default and ignores the rest of the switch statements.
Board_Talk
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon May 03, 2004 6:37 am

Postby gesf » Mon May 03, 2004 7:26 pm

Ok sorry!
So, try to use:
Code: Select all
switch($_POST['act'])
Instead of:
Code: Select all
switch($act)
Please read this post, so you can know what i´m talking about!

In the code above, use $_GET / $_POST, depending on your form method, when submiting data via form. Otherwise use $_GET or $_REQUEST!
User avatar
gesf
Moderator
Moderator
 
Posts: 1718
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby Board_Talk » Tue May 04, 2004 7:18 am

Thanks for the patience here. I read and tried the script given on the post you advised as shown below:

<?php
session_start();
if(!isset($_POST['submit']))
{
if(empty($_POST['post_firstname']) || empty($_POST['post_lastname']) || empty($_POST['post_email'])) $_SESSION['error'] = '<strong>You must enter all information</strong>';
else
{
echo 'First Name: '.$_POST['post_firstname'].'<br>';
echo 'Last Name: '.$_POST['post_lastname'].'<br>';
echo 'Email Address: '.$_POST['post_email'].'<br>';
exit;
}

}

{
if(!empty($_SESSION['error'])) echo $error;
$_SESSION['error'] ='';
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
First Name: <input type="text" name="post_firstname" <?php if(!empty($_POST['post_firstname'])) echo 'value="'.$_POST['post_firstname'].'"';?>><br>
Last Name: <input type="text" name="post_lastname" <?php if(!empty($_POST['post_lastname'])) echo 'value="'.$_POST['post_lastname'].'"';?>><br>
Email: <input type="text" name="post_email" <?php if(!empty($_POST['post_email'])) echo 'value="'.$_POST['post_email'].'"';?>><br>
<input type="submit" name="submit" value="submit"></form>
<?php
}
?>

I am able to get the form to show properly, but according to the way the script should run I should not be allowed to have any empty text areas. When I click submit with any or all of the form fields empty I simply get the form back again the same way I posted.

I should note that because I am on WinXP pro, I had to install PHP manually. Therefore, as well, I had to change the php.ini to my settings. I have seen some parts of the php.ini that call for output handlers and such. As I am an excellent php programmer but not a very good php administrator, I am completely lost in deciding what some of the variables should be.

I have RTFM countless times and will continue to do so as I love the knowledge but in trying to get this ready in a timely manner, all your help is very much appreciated. If my current workload were not so huge I am sure I would have had this solved already, but unfortunately, I have my job to think about too.

Thanks again for all your patience. :-D
Board_Talk
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon May 03, 2004 6:37 am

Postby gesf » Tue May 04, 2004 8:44 am

No, it has nothing to do with the php.ini or even your OS.
There´re just a few things you should change.

1st:
Code: Select all
Replace you 1st if statement with:

if(isset($_POST['submit']))

// removed the ! (NOT)


2nd:
Code: Select all
You´re assigning your error message to a session variable, so that you better register it first, like:

session_start();
session_register('error');


3rd:
Code: Select all
Replace your code:

// Here, you´re print an Undefined variable: error!
if(!empty($_SESSION['error'])) echo $error;

With:

if(!empty($_SESSION['error'])) echo $_SESSION['error'];

It should work!
Anyway, i think there´s no need for using sessions here. You can simply assign the error message to a variable and print it, like:
Code: Select all
$error = '<strong>You must enter all information</strong>';

...

if(!empty($error)) echo $error;


Greetz,
gesf
User avatar
gesf
Moderator
Moderator
 
Posts: 1718
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby Board_Talk » Tue May 04, 2004 10:29 am

Is there a difference between PHP 4.3.3 and PHP 4.3.6 with the methods you explained above? My host still uses PHP 4.3.3.

I have all my source on one .php page and a switch to drive them all. I know it's a huge page but I like it that way. With the methods you've described above I can at least drive the switch properly, however, the page views still come up empty. ex:(http://localhost/folder/page.php?act=view&PkId=1438) Keep in mind this is just a link and not a form within the code. Do I need to now place all my links within a form?

On a <form method=post> it does not enter the data but the form does show up at least. Do I now need to specify differrent switches to $_POST or $_GET? The code in reference uses no sessions so I am clear of that issue. It does use alot of forms for certain areas and I have quite a few parts that should simply show data. When I click on the "View" or "Edit" sections the page comes up empty still.

Looks like I'll need to start referring to the newer manual for home dev use and use the older manual for the past dev projects. Seems I'll have alot of angry customers should the host ever upgrade. :shock:

Anyway, thanks again for all the help. You've managed to point me in the right direction.
Board_Talk
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon May 03, 2004 6:37 am

Postby gesf » Wed May 05, 2004 4:20 am

Yeh, there´re are some, or even a lot of little differences between PHP 4.3.3 and PHP 4.3.6.
Don´t ask me what are the differences, i really don´t know, but let´s say... in some functions. You´ll probably find some of them when working with more php's functions. But forget, they aren´t in statements like switch´s or if´s...

Well, about your switch problem, let´s say you´re looking for this: act=view&PkId=1 and you´re only cheking for act=view!

You can make something like (example):
Code: Select all
<?php
...

switch($_GET['act']) {

$PkId = $_GET['PkId'];

case "view":

/* And sending your 2nd variable as a parameter of your view_Selection() function */

view_Selection($PkId);

break;

...

?>
User avatar
gesf
Moderator
Moderator
 
Posts: 1718
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden


Return to PHP Installation

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.