Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

[web] php problem

Started by FreJa Oct 12, 2006 at 4:32 AM 8 replies 1k views
Original Post
FreJa
FreJa
Hey, My index.html:

<html>
<body>
<form method="POST" action="process.php">
<textarea rows="3" name="p12" cols="35"></textarea>
<input type="submit" value="Submit" name="B1">
</form>
</body>
</html>
My process.php:

<?php
echo $p12;
?>
shouldnt this show the contents of what I wrote in my textarea in index.html? however, I just get a blank page. Any help? Thanks
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."
markr
markr
There are two problems here:

1. You are assuming that the obsolete feature register_globals is enabled. This is an obsolete feature and is now disabled by default. Use $_GET or $_POST etc instead (read the chapter about superglobals in the docs)

2. Your error reporting level is not high enough, or you would have spotted the notice telling you about the uninitialised variable.

All PHP applications should always work with error_reporting(E_ALL) and produce no notices, errors or warnings during normal operation - in fact I typically install an error handler which causes the page to bomb out if any of those happens, even E_NOTICE, which typically indicates a real problem which needs to be fixed.

Mark
FreJa
FreJa
thanks! that solved the problem.
one more thing though: what about this, shouldnt this work:

process.php
<html><head></head><body><?php$fh = fopen("test.txt", 'w') or die("can't open file");fwrite($fh, "howdy");fclose($fh);?><table align="center" width="100%"><tr><td>Thanks!</td></tr></table></body></html>


test.txt having all the permissions, it still outputs: "can't open file" ...
help?

thanks again :D
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."
DJHoy
DJHoy
Quote:
Original post by FreJa
<?php$fh = fopen("test.txt", 'w') or die("can't open file");fwrite($fh, "howdy");fclose($fh);?>

test.txt having all the permissions, it still outputs: "can't open file" ...
help?


FreJa - did you try using the full path to where you want test.txt placed? Many times, without this it will try and write the file to wherever the httpd server is running, not where the .php file is at.


Mathachew
Mathachew
Does the file already exist? (going by your text, it does).
Do you have write permissions on the folder (should only apply if the file doesn't exist)?

Is the text file in the same folder as the php file?
Are you including the php file from a different file that exists in a separate directory?
FreJa
FreJa
i have all the permissions, I set the full path.
I tried using "rb" in fopen instead of 'w' or "wb" and it didnt give any error, but it didnt write to the file either... :(((

help!!
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."
Verminox
Verminox
Are you sure you got the case right as well? Some platforms may not consider "test.txt" and "test.TXT" as the same thing.

Also, try using "r+" or "w+".
--------------------------------------Amaze your friends! Astound your family! Kennify your text!
izua
izua
well, if it's not something really complex you need written in a file, you can alway use file_get_contents and file_put_contents. (for more complex stuff, i'd recommend a database)
you simply give the name of the file, and it returns you their complete contents, without asking for a write mode, open mode, etc.
put_contents overwrites (creates if doesn't exist) any file, so you don't have to care about appending or other nasty stuff either.

as for the path, you can always use ./file.txt if you are reffering to something in the same dir as the script, but it just doesn't appear to be there.

izua
FreJa
FreJa
ok, i gave up on that server and switched.
Its working now, but I'm having another php prob. I have 10 checkboxes, they all belong to a group so I gave them the same name attribute, but a different value one. How do I, in php, only get the ones that are checked?

Thanks again
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."
izua
izua
Quote:
Original post by FreJa
ok, i gave up on that server and switched.
Its working now, but I'm having another php prob. I have 10 checkboxes, they all belong to a group so I gave them the same name attribute, but a different value one. How do I, in php, only get the ones that are checked?

Thanks again


what do you mean the same name attribute?
you should give them names like "check[1]","check[2]" for easier access in php.

the ones that are checked will return "on" in $_POST, for example, if check[2] was clicked, $_POST[check][2] will return "on".
However, if they won't be clicked (or checked and then, unchecked), the variable won't even be set.
Though it's a bad practice, i just check if they == "". But you should use isset() and check if they are null, or simply check if they are !="on", case which will be assumed by default unchecked.

izua

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.