PHP, MYSQL and Multiple Records revisited
| From: | Curtis | Date: | Tue, 03 Apr 2001 01:25:42 +0000 |
| Subject: | PHP, MYSQL and Multiple Records revisited | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-46738@lists.php.net to get a copy of this message | ||
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