which module for an APACHE local server

sadstoryitis

Registered
I have been having problems with my [ MAMPP/XAMPP ] local APACHE server, which includes PHP n MYSql, but it seems that i cannot really use this as my local server for my PHP files, because the local server doesnt recongize the variables sent from the html forms.

So I'm asking, is there any other programs which i can create a local server environment for a testing server, which i will test my files on locally. Or is there any way that i can establish a local server inside MACOSX without installing anything?

And finally, if any of you know how to fix the mampp local apache server problem that i m having right now, not able to get any variables from a submitted html form, lemme know. :D
 

Pengu

Digital Music Pimp
when you say it doesn't recognise the variables, how are you trying to access them?

by default, newer PHP builds have register_globals set to off, meaning to access form fields, you need to use either $_GET[fieldName] or $_POST[fieldName] as opposed to $fieldName

You can turn register_globals back on, but i'd suggest just using the more secure method to access the data. It prevents someone from adding variables to a url that has been processed as a POST..

hope this helps..
 

sadstoryitis

Registered
im a bit of a newbie at php, and i know what you are talking about, believe me, i have tried both methods and it does not work. let me show you an example of what i have been attempting to success at:

"myname.php"


<body>

hello

<?php print $_POST['myname']; ?>


.
</body>

-----------------------------------------------

"yourname.htm"

<body>
<form action="myname.php" method="get">

<input type="text" size="40" name="myname">
<input type="submit" value="submit">


</form>
</body>


I assume that the format is correct, but each time i type anything in the text box and hit submit, the variable within the box doesent show up in the myname.php. So what should you suggest, should i uninstall my local server enviroment and install an other program for a local server environment or what?

thanks.
 

Pengu

Digital Music Pimp
ok. firstly, try this on your php script:

<?php echo( $_GET[myname] ); ?>

then view the source. post back what you get.
 

sadstoryitis

Registered

<body>

hello

adfadf
.

</body>


tada. it works now.. im asking this, can i use the print function instead of echo? and hm if i wanted to use print instead of echo i would have to only replace echo with print or what? and what did i do wrong in the previous codes?
 

Pengu

Digital Music Pimp
um. not sure. print and echo aren't exactly the same. this page describes the differences.
 

elander

Registered
You're using the method 'GET' in your form, which isn't recommended. First of all, it doesn't allow as much data as the 'POST' method, and second, it leads to long and unsightly urls in the browser window. There are also security issues, that I won't go into.

Once you change the method to 'POST', you can access the field variables through $_POST['variable_name'] (substitute 'variable_name' for the actual name of the variable).

If you want a quick way to really get up to speed on PHP and MySQL, I would recommend the PHP Anthology, vols I and II from Sitepoint. I'm in no way affiliated with them, but I really like their books, the most unboring and bang-for-the-buck books I've found, and I've done a lot of searching.
 

Pengu

Digital Music Pimp
for a simple site, i would avoid the post method. Firstly: a lot of browsers will ask you "are you sure you wish to submit this form. it is not secured" or whatever, because you aren't using https://. GET will never do that. Secondly: if using PHP to make a template system, visitors can bookmark pages accessed through GET. they can't bookmark the result of a POST form. Thirdly: you can mix hyperlinks and Javascript with forms, when sending a visitor to a page, the same is nowhere near as easy with POST.
 

elander

Registered
Pengu said:
for a simple site, i would avoid the post method. Firstly: a lot of browsers will ask you "are you sure you wish to submit this form. it is not secured" or whatever, because you aren't using https://. GET will never do that. Secondly: if using PHP to make a template system, visitors can bookmark pages accessed through GET. they can't bookmark the result of a POST form. Thirdly: you can mix hyperlinks and Javascript with forms, when sending a visitor to a page, the same is nowhere near as easy with POST.
Well, I sort of agree, and also disagree.

I'll start by disagreeing:
In forms where the user is submitting data that is to be stored on the server (such as in a user database or similar), you should never, ever use GET. Browsers may reload a GET URL automatically, particularly if cacheing is disabled (as is usually the case with dynamic output), without notification. It will typically prompt the user before re-submitting a POST request, even when the user tries to reload tha page manually. This means you're far less likely to get inadvertently-repeated entries from POST.

And here comes the agreeing part:
In forms where nothing of the submitted matter is stored on the server, i.e. search forms and such, by all means use GET if you like. As you stated, that gives the user a chance to bookmark the resulting page.
 

sadstoryitis

Registered
Thank you all guys for the explaintation on GET n POST functions. Now, im asking this- how do you make a script to store data on a database?
 

elander

Registered
Before you get started on scripts to store and retreive information, get to know SQL well. It'll take a couple of hours if you're used to any kind of programming, longer if you're a total beginner.

Start here: http://sqlzoo.net

Go to this site, and work through the examples in sections 1 through 6 on the left. Read the reference sections on the right first, at least cursively, so you know where to find the information you need when you get stuck later on.

When you understand the examples on this site, you are ready to move on, and create your own databases. Continue here:
http://http://db.grussell.org/

Read (at least) the chapter on "Normalization", and you have a good start in creating working databases.

Now you'll want to start connecting to your database from PHP. That's the easy part. Move on to this site, and do the stuff in chapter 4:
http://www.php-mysql-tutorial.com/

Come back in a week or so, and let us know how it went...:D
 
Top