Hi--
I'm trying to use a simple form to create and input and store data in an array in a Mysql table. I want to be able to go back to the form at any time and add more elements to the array. And then to search for an element in the array. I have a form page and a processing page, below. When I try to submit the form I get this error:
Warning: implode() [function.implode]: Bad arguments. in /home/freeest/public_html/do_blackout.php on line 10

What am I missing? Thanks.

 My Form
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form method="POST" action="do_blackout.php">
<input type="text" id="blackout_date[]">
<input type="submit" name="submit">
</form>

</body>
</html>

[code=php] My Action Page
<? include('connect.php'); ?>

<?php

$blackout_date=implode(",", $_POST['blackout_date']);

$sql = "INSERT INTO blackout SET
blackout_date='$blackout_date'
";

?>

    the POSTED field should have 'name'
    and I think you should use simply 'blackout_date' ( not with[] )

    <form method="POST" action="do_blackout.php">
    <input type="text" id="blackout_date" name="blackout_date">
    <input type="submit" name="submit">
    </form>

    Question is if you can use arrays.
    Both the form and the database should handle strings?

    When you take the commaseparated string from the database later,
    you may explode it into an array.

      I made the changes you suggested but I'm still getting the same error. Any other ideas? Thanks.

        what i meant is:

        you enter a string:
        asdfg,wert,34,ert

        now implode needs an array as argument, not a string
        when we submit a post field we enter a string

        this is why you should remove implode() line

        later you can take this string, from DB
        and turn it into an array, using:

        $myarr = explode ( ',' , $blackout_date ); // asdfg,wert,34,ert
        will make
        $myarr[0] = 'asdfg';
        $myarr[1] = 'wert';
        $myarr[2] = '34';
        $myarr[3] = 'ert';

          Thanks for your answer. I think I understand. But how, in the future, would I then add more elements to the string in the row while still maintaining the elements that are already there? I can't seem to find how to do that in the documentation. Thanks.

            you first get your string from db
            put this in a variable
            lets call it $blodate,

            first time it will be empty, $blodate= '';

            Then when you display form you put this value in

            <form method="POST" action="do_blackout.php">
            <input type="text" id="blackout_date" name="blackout_date"
             value="<?php echo $blodate; ?>">
            <input type="submit" name="submit">
            </form>

              Alternatively you can use the mySQL command CONCAT():

              UPDATE `table` SET `blackout_dates` = CONCAT(`blackout_dates`, ',', '$new_dates')

                Would you mind marking this thread "resolved"?

                  Write a Reply...