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

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -

jQuery clickable div with working mailto link inside -