running apache/MySQL/PHP locally on OSX. (1 Viewer)

plug

Well-Known Member
Joined
Feb 11, 2003
Messages
6,046
Location
dublin/cork
Website
www.outonalimbrecords.com
got round to trying this out on saturday. being new to all this shit, I finally got it up and running (or so I thought) after some head scratching. so I had my sites directory containing some .php files, and they were displaying fine. the only problem is that they weren't executing at all. for example, simple things like checking whether or not a textfield was empty. nada.

all the php is fine, I originally wrote them on the server here at work, they worked and continue to work okay. it's all really simple stuff, as I'm just learning, but I'm reasonably positive that's not the problem. it makes me suspect that somewhere along the road, I either fucked up installing something or forgot to do something... I'm a little baffled to say the least.

I know this is vague as fuck, but has anyone else ever come across this/have any advice or ideas? should I be looking at uninstalling/reinstalling shit?

help! thanks. dar
 
sorry about being so vague. what I mean is that php files will display fine offline in my web browser, if I go to http:localhost/myFileName.php the file will be found, read and displayed properly. but there's no functionality. that's the problem. for example, even something really, really basic like this:

PHP:
<?

echo "<p>myTest</p>";

// 

$displayForm = "<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">

enter your name: <input type=\"text\" name=\"myField\" value=\"$myField\" />

<input type=\"hidden\" name=\"myFormSend\" value=\"yes\" />
<input type=\"submit\" name=\"submit\" value=\"submit form!\" />

</form>";

//

echo $displayForm;

if($myFormSend == "yes") {
	
	// make sure field is not blank!
	
	if ($myField != "") {
	echo "<p>your name is $myField.</p>";
	} else {
	echo "<p>tell me your name!</p>";
	}
}

?>

doesn't work. at all. instead, the page reloads on button click. knowharramean? is this extremely odd behaviour?
 
You have register_globals turned off in php.ini I would say.
What this means is that you can't read form data in the way that you're trying to - when your form is submitted when register_globals is turned on, $myFormSend will be equal to "yes", but when it's turned off it will be empty. This is actually correct, and the recommended way to set up php - you need to use the $_POST superglobal array to access your form variables:
PHP:
<?php

echo "<p>myTest</p>";

// 

$displayForm = "<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">

enter your name: <input type=\"text\" name=\"myField\" value=\"$_POST[myField]\" />

<input type=\"hidden\" name=\"myFormSend\" value=\"yes\" />
<input type=\"submit\" name=\"submit\" value=\"submit form!\" />

</form>";

//

echo $displayForm;

if($_POST[myFormSend] == "yes") {
    
    // make sure field is not blank!
    
    if ($_POST[myField] != "") {
    echo "<p>your name is $_POST[myField].</p>";
    } else {
    echo "<p>tell me your name!</p>";
    }
}

?>
 
ah... just having a quick peek in work here, will be having a better look after six, but things seem to be working here... thanks egg_!

re: keeping html outside php tags - would that include text formatting tags like <p> etc.?

think I need to invest in a good book or something.
 

Users who are viewing this thread

Activity
So far there's no one here
Old Thread: Hello . There have been no replies in this thread for 365 days.
Content in this thread may no longer be relevant.
Perhaps it would be better to start a new thread instead.

21 Day Calendar

Lau (Unplugged)
The Sugar Club
8 Leeson Street Lower, Saint Kevin's, Dublin 2, D02 ET97, Ireland

Support thumped.com

Support thumped.com and upgrade your account

Upgrade your account now to disable all ads...

Upgrade now

Latest threads

Latest Activity

Loading…
Back
Top