Search code examples
phpfwrite

PHP fwrite writes 0 bytes


I have tested this over and over and for some reason the code writes 0 on my file but when i do echo it writes the intended text.

HERE IS MY CODE:

<?
$author = $_POST["author"];
$email = $_POST["email"];
$comment = $_POST["comment"];
if (isset($author) && isset($email) && isset($comment)) {
    $fileWrite = fopen("Archivo/comentarios.txt","a");
    $bytes = fwrite($fileWrite,$author + "*" + $email + "*" + $comment + "\n");
    fclose($fileWrite);
}

header('Location: http://www.empowernetworkmexico.com.mx/contacto.php');
?>

<html><head></head><body>
<?
    echo $author;
    echo $email;
    echo $comment;
?>
</body></html>

I tested using "TEST" as the text value for every parameter on my submit form.


Solution

  • plus + is not for concat use . instead. see this page for more information about concatenation operator ('.') http://www.php.net/manual/en/language.operators.string.php

     if (isset($author) && isset($email) && isset($comment)) {
       $fileWrite = fopen("Archivo/comentarios.txt","a+");
       $bytes = fwrite($fileWrite,$author . "*" . $email . "*" . $comment . "\n");
       fclose($fileWrite);
    }