Okay, with all that code, I can answer your question.
The problem here is that you only have  on form field with a date. Therefore
it should not be an array.
You also have only one photono, so it too should not be an array.

When the loop iterates to create the query, there is only a value for the
first item in the photono and photodate arrays. All subsequent iterations
will have null values, therefore, the query will insert the first data set,
and error out on the following ones.

Replace this:
> $result = mysql_query($query);
With this:
Print $query

And the query will output to the browser, and you will see the empty values.
On deeper thinking, do you have a whole lot of empty fields if you manually
do a SELECT * FROM pictures; ? Or is one of the following defined as not
null (photono,photodesc,photodate) . If one of those is not null, I think it
would error out the query after the first insert.

Even though there is an error in a multiple insert like this, it still
inserts up to the point it errors.


On 4/2/01 6:25 PM, "Curtis" <[EMAIL PROTECTED]> wrote:

> Ok,
> Here is the code I am using to insert values from a form into a mysql
> database...
> (Given to me by Lindsay Adams,, thank you!)
> This is just a phantom form and database, there are several things you
> could look at
> right off the bat and ask "Why is this fool doing this"
> Don't bother I already asked that.
> 
> I want to be able to input a picture number, date and up to 5
> descriptions,
> If I enter a PHOTONO, two - DESCRIPTIONS, and a DATE
> the code only shows one entry...
> 
> Any ideas where I am going wrong?
> ========= START CODE ========
> <html>
> <head>
> <title>My Pictures</title>
> </head>
> <body color="#FF00FF">
> <?
> if(isset($submit)):
> $db = mysql_connect("localhost", "root");
> mysql_select_db("photo", $db);
> 
> 
> $query = "INSERT INTO pictures (photoid, photono, photodesc, photodate)
> VALUES";
> for($I=0;$I < count($photono); $I++) {
>       if(!($I == count($photono) - 1)) {
> $query .="(NULL,'$photono[$I]','$photodesc[$I]','$photodate[$I]'),";
> }
> else {
> $query .="(NULL,'$photono[$I]','$photodesc[$I]','$photodate[$I]')";
> }
> }
> $result = mysql_query($query);
> 
> print("<h2>The data has been entered</h2>\n");
> 
> endif;
> 
> ?>
> <form action="http://localhost/pic2.phtml" method="post">
> Picture Number:<br><input type="text" size="20" name="photono[]"><p>
> Picture Description:<br><input type="text" size="40"
> name="photodesc[]"><p>
> Picture Description:<br><input type="text" size="40"
> name="photodesc[]"><p>
> Picture Description:<br><input type="text" size="40"
> name="photodesc[]"><p>
> Picture Description:<br><input type="text" size="40"
> name="photodesc[]"><p>
> Picture Date:<br><input type="text" size="8" name="photodate[]"><p>
> <input type="submit" name="submit" value="Submit Picture">
> </form>
> </body>
> </html>
> ========You guessed it End Code=========
> 
> Thanks in advance
> Curtis
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to