Jump to content

[SOLVED] Problem with PHP script


peddel

Recommended Posts

On the moment im working on something for a company.

They assigned me a company computer that i could use and configure my wantings.

Since i started i have had problems with forms, things i never had problems with before on my own pc!

Every time i run the script, it does not react to my php code after submitting the form !

Can someone explain me what can be the problem?

 

Im using Aptana - php environment for making my code.

Under here is the simples form i could think of, yet it does not work !

Anyone wanna give me push in right direction?

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

</head>

<body>

<form id="test" method="post">

<input type="text" name="field"></input>

<input type="submit" name="button" value="press here"></input>

<input type="hidden" name="hidden" value="1"></input>

</form>

</body>

<?php

if($_POST[hidden] == 1) {

print("U typed : ".$_POST[field]);

}

?>

</html>

 

Till now this has worked for me, but it can be im making a huge mistake!

Hope to get some answers soon :)

Link to comment
https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/
Share on other sites

Your form doesn't have an action, maybe?

 

<form id="test" method="post" action="">

 

>___< indeed it doesnt :)

Thing is, it always worked without, by using that hidden variable so i learned it the wrong way i guess

What should i add at the action item to make it work?

put blank, if you have the after action code in the same page (like urs), like

 

<form id="test" method="post" action="">

 

if you have ur after action code in any other page, just mention that page in action, like

 

 

<form id="test" method="post" action="actionpage.php">

 

btw, as far as I know, it works without action as long as you have your "after form submit" code in the same file.

Okay well first up, your HTML is wrong. <input> tags are self closing, so you don't need the </input>

Example:

<input type="text" name="something" id="something" />

 

You can make the action for the form tag this:

<?php echo $_SERVER['REQUEST_URI']; ?>

 

I don't like to leave it blank. :)

 

You don't have to use a hidden field either. You can get the value of a submit button $_POST. So because it has a value, when they submit the form it will always have the value. So instead of checking the hidden value to be one you can check:

if(isset($_POST['button'])){

 

That will check to see if the variable is set.

 

One more thing, when refering to array keys, which is the field name. You have done it like this:

$_POST[field]

 

You should wrap it in quotes so that PHP doesn't think it is a constant.

So it should become this:

$_POST['field']

 

Good luck. :)

Well i changed the code to the following :

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body>
	<form id="test" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
		<input type="text" name="file" />
		<input type="submit" name="button" value="Press here" />
	</form>
</body>
<?php
    if(isset($_POST['button'])){
    	print("Ur message : ".$_POST['file']);
    }
?>
</html>

 

Let me stress out that im using aptana, a php devellopment tool.

I just use the internal server to test inside the program.

It is using firefox to show the result.

 

When i press the button now i get a new page with the message :

Can't find page ...

 

Any ideas?

You could also try temporarily changing your methods from POST to GET so you can read it in your address bar and see if theres anything funky there... so you should end up with something like script.php?hidden=foo. Dont forget to change $_POST to $_GET if you do that tho...

 

Also, try replacing "$_SERVER['REQUEST_URI']; " with $_SERVER['PHP_SELF']; or just the name of your page, script.php will work just fine if thats the name of yoru script.

Didnt think of that.  If its older and REGISTER GLOBALS is turned on, you could try replacing $_POST wiht $HTTP_POST_VARS['fieldname'] also...

 

If thats the case and HTTP_POST works and $_POST doesnt, plug this in up at the top:

 

$_POST = &$HTTP_POST_VARS;

 

If that's the case then I would recommend upgrading the version of PHP.

Ok got WAMP2.0 going !

It clearly worked fully when testing under WAMP, sad i didnt come up with this.

I just dont get why Aptana doesnt work, cuz it uses the same browers.

Anyone got clue how maybe to solve the problem in aptana?

If not ill just check my pages with wamp :)

 

I've never used Aptana so I would have no idea. I've always used WAMP.

 

Well thank you for the help.

I never used Aptana at school either, just wamp to test and eclipse to write my php code.

It was a friend who showed me the aptana plugin for eclipse.

That grew my interest so i dled the free standalone version.

Tough now it seems that it has some flaws, no idea how to fix em :D

 

Thx to everyone for the advice !

U guys will be hearing soon from me again with new php problems :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.