RE: [PHP-DB] mysql and php
| From: | Lars Wilhelmsen | Date: | Mon, 17 Jul 2000 17:10:39 +0000 |
| Subject: | RE: [PHP-DB] mysql and php | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-1198@lists.php.net to get a copy of this message | ||
Hi Joanna.
I wouldn't done it this way, but:
<?
if ( $go )
{
mysql_connect( "host", "user", "password" );
mysql_select_db( "fruitdb" );
$query_id = mysql_query("INSERT INTO FruitTable(fruit)
VALUES('$fruit')")
or die( "Could not insert record, dying like a dog..." );
?>
<html>
<form action=<?= $PHP_THIS ?> method="post">
<select name="fruit">
<option name="apple">Apple</option>
<option name="banana">Banana</option>
<option name="pear">Pear</option>
</select>
<input type="submit" name="go" value="Go!">
</form>
</html>
#
# sql file
#
CREATE DATABASE fruitdb;
CREATE TABLE FruitTable(
id int not null auto_increment primary key,
fruit varchar(20),
other fields...
....
);
It would be better if you create a table in your db with.
1 Apple "apple description"
2 Banana "banana description"
3 ...
And generated the <select></select> tag from it.
if you got the table def:
create table fruittable(
id int not null auto_increment primary key,
name varchar(30),
descr varchar(50));
You could genererate the <select></select> box with:
openDB();
$query_id = mysql_query( "SELECT * FROM fruitable" );
echo "<select name=\"fruitchoices\">";
for ($i = 0; $i < mysql_num_rows( $query_id ); $i++)
{
$row = mysql_fetch_array( $query_id );
$id = $row["id"];
$name = $row["name"];
echo "<input name="$id">$name</input>";
}
echo "</select>";
then you could check for fruitchoices=1...n where the number would
be the corresponding row in your fruittable - which you again could
use for insertion into other tables (phew! )
ok.. Regards,
-larsw-
--
Lars Wilhelmsen <lw@ez.no>, developer @ eZ systems <www.ez.no>
-----Original Message-----
From: Joanna [mailto:joanna@blackhole.evilgeeks.com]
Sent: 17. juli 2000 19:02
To: php-db@lists.php.net
Subject: [PHP-DB] mysql and php
I have a db with a simple table. One of the fields in the tables are
fruit. I created a HTML SELECT FORM to select what kind of
fruit,apples,peaches,ect... I would like to input the kind of fruit into
the table. I have even tried using php ifelse statements to assign
integers instead of the actual fruit name and I still can't figure it
out. Can someone please help.
The thing I can't figure out is how to know which of the choices have been
selected from the form.
thanks
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
For additional commands, e-mail: php-db-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net