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 Quote Link to comment 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']}"; } Quote Link to comment 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! Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
messi1 Posted March 12, 2011 Author Share Posted March 12, 2011 ok, thank you for the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.