HaxorNab Posted December 11, 2016 Share Posted December 11, 2016 (edited) Hi again fellas.Ill make it quick. I attached photo and here is the code. I am braking my head about 2 hours on how to fix those errors and bumped into dead end :s <form method="get"> Tekstą:<br> <textarea name="cont" rows="5" cols="60"></textarea> <br>Įrašyti į failą: <input type="text" name="text" value="">.txt <br><input type="radio" name="1" value="1">1 <input type="radio" name="2" value="2">2 <input type="radio" name="3" value="3">3 kartus <br><input type="submit" name="4" value="Įrašyti"> </form> <?php $file=$_GET['text']; $vk=fopen($_SERVER['DOCUMENT_ROOT']."/".$file.".txt","wb"); // pasiremta http://stackoverflow.com/questions/9265274/php-create-and-save-a-txt-file-to-root-directory if ($_GET['1']) { fwrite($vk,$_GET['cont']); fclose($vk); echo "<br>Failas "."<b>".$file."</b>".".txt papildytas tekstu: "."[<b>".$_GET['cont']."] "."1"."</b>"." kart.";} elseif ($_GET['2']) { fwrite($vk,$_GET['cont']); fwrite($vk," ".$_GET['cont']); fclose($vk); echo "<br>Failas "."<b>".$file."</b>".".txt papildytas tekstu: "."[<b>".$_GET['cont']."</b>] "."2"."</b>"." kart.";} elseif ($_GET['3']) { fwrite($vk, $_GET['cont']); fwrite($vk," ".$_GET['cont']); fwrite($vk," ".$_GET['cont']); fclose($vk); echo "<br>Failas "."<b>".$file."</b>".".txt papildytas tekstu: "."[<b>".$_GET['cont']."</b>] "."3"."</b>"." kart.";} ?> I would really apreaciate your help fellow programers not noob as me ofc Edited December 11, 2016 by HaxorNab Quote Link to comment https://forums.phpfreaks.com/topic/302716-undefined-offset/ Share on other sites More sharing options...
benanamen Posted December 11, 2016 Share Posted December 11, 2016 (edited) You are not doing any checks to see if the form has been submitted so the entire code runs before you doing anything. Look up and learn about isset. There are other problems I am sure others will tell you about. Edited December 11, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/302716-undefined-offset/#findComment-1540208 Share on other sites More sharing options...
HaxorNab Posted December 11, 2016 Author Share Posted December 11, 2016 (edited) Yes. I already found my mistake. Thanks for trying to help I made same radio names and added if ($_GET['1'] == (radio value)) and its all perfect Edited December 11, 2016 by HaxorNab Quote Link to comment https://forums.phpfreaks.com/topic/302716-undefined-offset/#findComment-1540209 Share on other sites More sharing options...
benanamen Posted December 11, 2016 Share Posted December 11, 2016 (edited) Yes. I already found my mistake. Thanks for trying to help I made same radio names and added if ($_GET['1'] == (radio value)) and its all perfect That is still wrong. $_GET can have numerous parameters. You are missing a name such as id=1. In your case it is name=1. You should probably be using POST instead of GET. <?php if (isset($_GET['name'])) { if ($_GET['name'] == 1) { //do something } if ($_GET['name'] == 2) { //do something } if ($_GET['name'] == 3) { //do something } } ?> Edited December 11, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/302716-undefined-offset/#findComment-1540214 Share on other sites More sharing options...
Jacques1 Posted December 11, 2016 Share Posted December 11, 2016 More importantly, you need to start thinking about security and robustness. Websites are public, which means you'll get all kinds of requests from all kinds of sources. Not all of them are valid and friendly. There will be invalid requests, malformed input, automated attacks and maybe even targeted attacks. Your application has to survive those. Right now, the script has no security or robustness whatsoever. Anybody can write arbitrary data to arbitrary files without any validation. They can upload malware, overwrite existing files and even leave the document root to screw up your server (nothing prevents them from using “../” in the filename). On top of that, the code is wide open to cross-site scripting attacks. Programming is a lot more than making error messages go away. You need to actually think about what you're doing (yes, even as a newbie). In your specific case, I recommend you forget about creating files on your server. It's simply too dangerous as long as you don't understand the implications. You should store the text in a database instead. I'm sure you have one installed already. Quote Link to comment https://forums.phpfreaks.com/topic/302716-undefined-offset/#findComment-1540218 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.