Mememe Posted October 4, 2007 Share Posted October 4, 2007 Hi.I have a index page called index.php, which I can post information, from page called posting.php This is posting.php <form method="post" action="index.php"><input type="text" name="title" value="Title of news" style="width: 449px" /><br/><br/><input type="text" name="user" value="Your name" style="width: 449px" /><br/><br/><textarea name="news" cols="50" rows="5" >News in here</textarea><br/><input type="submit" value="Submit news" /></form> So once the data is entered, it goes to index.php, and in index.php, I have $curpost = $_REQUEST['news'];$curpname = $_REQUEST['user'];$curptitle = $_REQUEST['title']; But whenever I load index.php, not post from posting.php, the errors come up: Notice: Undefined index: news in C:\Program Files\EasyPHP 2.0b1\www\GMScripts Database\index.php on line 120Notice: Undefined index: user in C:\Program Files\EasyPHP 2.0b1\www\GMScripts Database\index.php on line 121Notice: Undefined index: title in C:\Program Files\EasyPHP 2.0b1\www\GMScripts Database\index.php on line 122 It's because no data was received from the posting.php, I think. Is there a way to stop these errors, if I'm not posting?Another thing is with fread(), for the how much bytes to be read, I have filesize('posts.txt') to read it all, but sometimes it comes up with this error Warning: fread() [function.fread]: Length parameter must be greater than 0 in C:\Program Files\EasyPHP 2.0b1\www\GMScripts Database\index.php on line 127 Does anyone know a way to stop this. If anyone needs more info, just ask.Thanks, Mememe Link to comment Share on other sites More sharing options...
boen_robot Posted October 4, 2007 Share Posted October 4, 2007 I guess you may want to supply a default value in case no value is provided. You can easily do that like so: $curpost = (!empty($_REQUEST['news']) ? $_REQUEST['news'] : 'default value'); Repeated for the three variables and replacing "default value" with the real default value you want of course.You could also do many other things, like redirecting the user to the other page, show an error message saying a value must be provided, etc. etc.... it really depends on the application.As for the fread(), if you just want to get the whole contents, use file_get_contents(). In other cases, as the manual on fread() says, provide the "b" mode parameter as shown in those examples. Link to comment Share on other sites More sharing options...
Mememe Posted October 4, 2007 Author Share Posted October 4, 2007 The 'aplication' is basically from the posting.php, I can post news, which is posted on index.php, which is the first page. I'm testing, and I'll report back.[EDIT]About the rb, will it work still if I put it on an web server? Link to comment Share on other sites More sharing options...
boen_robot Posted October 4, 2007 Share Posted October 4, 2007 [EDIT]About the rb, will it work still if I put it on an web server?If the server is Windows - sure. If it's *nix... I'm assuming it will, but if it doesn't, I guess you'll have to manually make that change or make some sort of test for the OS. Link to comment Share on other sites More sharing options...
Mememe Posted October 4, 2007 Author Share Posted October 4, 2007 Okay, thanks. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 4, 2007 Share Posted October 4, 2007 You can also use isset to check if something is defined before you try to access it. So instead of something like this: $var = $_POST['name']; or this: if ($_POST['name'] == "test") you could do this: $var = "";if (isset($_POST['name'])) $var = $_POST['name']; if (isset($_POST['name']) && $_POST['name'] == "test") Link to comment Share on other sites More sharing options...
jhecht Posted October 5, 2007 Share Posted October 5, 2007 From the error, I'm getting that your version of PHP doesn't populate the $_REQUEST variable. You may want to use $_POST or $_GET(whichever one your form uses). If you want you can make your own $_REQUEST variable, it's pretty much just $_REQUEST = array_merge($_GET,$_POST,$_COOKIE); Personally, I wouldn't use $_REQUEST. I just don't like it quite honestly. Link to comment Share on other sites More sharing options...
Mememe Posted October 5, 2007 Author Share Posted October 5, 2007 Thanks for the tip. Oh, one last thing, how do I put " between ' '? Link to comment Share on other sites More sharing options...
jhecht Posted October 5, 2007 Share Posted October 5, 2007 $variable = ' \' hello there \''; echo $variable;That will output' hello there ' Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.