messi1 Posted March 12, 2011 Share Posted March 12, 2011 hi guys, i'm learning some php, and trying some things. but i can't seem to get this to work. <html> <title>simple thing</title> <body> <form action= 'blog.php' method = 'GET'> author: <input type='text' name="writer" /> <br/> article: <textarea rows="25" cols='60' name="article"></textarea> <input type="submit" value="send" /> </form> </body> <hr /> </html> <?php $writer = $_GET ['writer']; print "writer is " . $writer; ?> i want to get rid of the error. it works, but it show this error. have I used the $_GET correctly? I tried using isset() and empty(), but I think I didn't used those correctly. could you guys tell me how to fix this small thing. the error: http://i.imgur.com/DC8by.png it runs perfect, when I run it in phpED, but when running the file directly "like: http://localhost/blog.php" it gives the error. I also read somewhere this has to do with the version of php. php4 would ignore the error, and php5 shows the error. would you explain that a bit more, please? thank you Link to comment https://forums.phpfreaks.com/topic/230456-simple-thing-wont-work/ Share on other sites More sharing options...
Pikachu2000 Posted March 12, 2011 Share Posted March 12, 2011 Check to see if the variable exists before attempting to use it. if( isset($_GET['writer']) ) { echo "Writer is: {$_GET['writer']}"; } Link to comment https://forums.phpfreaks.com/topic/230456-simple-thing-wont-work/#findComment-1186749 Share on other sites More sharing options...
messi1 Posted March 12, 2011 Author Share Posted March 12, 2011 ah, ofcourse! thank you, I was creating a variable $writer, while php didn't knew if the GET existed. and I have to do this with $_POST too, right? thanks! Link to comment https://forums.phpfreaks.com/topic/230456-simple-thing-wont-work/#findComment-1186759 Share on other sites More sharing options...
Pikachu2000 Posted March 12, 2011 Share Posted March 12, 2011 Correct. Anytime you have a variable that may or may not exist at the point you need it, you should test for its existence first. Link to comment https://forums.phpfreaks.com/topic/230456-simple-thing-wont-work/#findComment-1186761 Share on other sites More sharing options...
messi1 Posted March 12, 2011 Author Share Posted March 12, 2011 ok, thank you for the help Link to comment https://forums.phpfreaks.com/topic/230456-simple-thing-wont-work/#findComment-1186762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.