Carlos Flores
Carlos Flores

Reputation: 29

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.

Upvotes: 0

Views: 1860

Answers (2)

mohammad mohsenipur
mohammad mohsenipur

Reputation: 3149

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);
}

Upvotes: 1

smassey
smassey

Reputation: 5931

The string concatenation operator in php is not "+" but instead ".". Looks like you have experience with JS or Python maybe..

fwrite($fileWrite,$author . "*" . $email . "*" . $comment . "\n");

Upvotes: 0

Related Questions