0

Hi, I have a problem with my code. When I fill the PHP form and submit on the page, I encounter with 2 problems;

1- It writes all 6 input coming from 6 textareas to next line in csv file as I want. But it writes all of them into the 1st cell of row I want it to write to 6 different cells of course.
2- After submitting the form, if you press backspace the form is opened again with the previous input in textareas, I want them to be empty. I'd appreciate if you help. Thanks.

3
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by jwales
0

my code is:

<?php
error_reporting(E_ALL ^ E_NOTICE); 

if($_POST['formSubmit'] == "Submit")
{
    $errorMessage = "";

    if(empty($_POST['formCase_No']))
    {
        $errorMessage .= "<li>You forgot to enter a Case Number!</li>";
    }
    if(empty($_POST['formCase_Description']))
    {
        $errorMessage .= "<li>You forgot to enter a Case Description!</li>";
    }
    if(empty($_POST['formCase_Info']))
    {
        $errorMessage .= "<li>You forgot to enter a Case Information!</li>";
    }
    if(empty($_POST['formCase_Customer']))
    {
        $errorMessage .= "<li>You forgot to enter a Case Customer!</li>";
    }
    if(empty($_POST['formCase_Date']))
    {
        $errorMessage .= "<li>You forgot to enter a Case Date!</li>";
    }
    if(empty($_POST['formCase_Note']))
    {
        $errorMessage .= "<li>You forgot to enter a Case Note!</li>";
    }

    $varCase_No = $_POST['formCase_No'];
    $varCase_Description = $_POST['formCase_Description'];
    $varCase_Info = $_POST['formCase_Info'];
    $varCase_Customer = $_POST['formCase_Customer'];
    $varCase_Date = $_POST['formCase_Date'];
    $varCase_Note = $_POST['formCase_Note'];

    if(empty($errorMessage)) 
    {
        $fs = fopen("filename.csv","a");
        fwrite($fs,$varCase_No . ", " . $varCase_Description . ", " . $varCase_Info . ", " . $varCase_Customer . ", " . $varCase_Date . ", " . $varCase_Note . "\n");
        fclose($fs);

        header("Location: thankyou.html");
        exit;
    }
}
?>
0

fopen

Hiii ,May you like to know about fopen here Click Here,read about it,i think you can use "w" or "x" instead of "a".
but instead of all that , if you use header function is better than file system functions:

<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-type: application/csv");
echo $varCase_No . ", " . $varCase_Description . ", " . $varCase_Info . ", " . $varCase_Customer . ", " . $varCase_Date . ", " . $varCase_Note . "\n";
?>

.
.
.
%%^Murtada^%%

0

Do you mean they all go in one cell in Excel when importing? If so, it's most likely the end-of-line. Try to output with \r\n instead of just \n.

0

pritaeas:

Do you mean they all go in one cell in Excel when importing? If so, it's most likely the end-of-line. Try to output with \r\n instead of just \n.

That's Okey, I am agree with you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.