php - Writing user input to a file -


the below code doesn't create info.txt file , dies: how can show error codes in such case - appending die command "."?

$morf .= $name ." ". $family; $morf .="with username " . $user; $morf .="  , password " . $pass; $morf .=" lives in " . $city;  $filelines = ""; if (file_exists("info.txt")) {     $filelines = file_get_contents("info.txt");     $filenewlines = $filelines . $morf . "\n";     file_put_contents("info.txt", $filenewlines);    } else {     die("something went wrong !"); } 

you can use try...catch have debugging information upon encountering error. also, not sure if intentional, logic there has script fail when file not exist. i've included allowance condition here, not if intent.

  try {     // not continue if file not exist     if (!file_exists("info.txt"))        die('something went wrong: file not exist');     // append data file     $filelines = file_get_contents("info.txt");     $filenewlines = $filelines . $morf . "\n";     file_put_contents("info.txt", $morf);          } catch (exception $e) {     // handle error      die("something went wrong: ".$e->getmessage());   } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -