
turpentyne
Members-
Posts
220 -
Joined
-
Last visited
Everything posted by turpentyne
-
hallelujah!!! the script Pikachu2000 posted is working. Now I have to go through it to see the differences between that script and mine, so I can understand where I was going wrong.
-
ah... I was changing the names of things 'to protect the innocent' and forgot one. that explains the plant_id. It is the same as item_id
-
thanks on the info for how to post code here. unfortunately, removing the exit(); didn't help. It still only posted one item, and gave me a huge list of errors about connecting to the database.
-
Sure... here it is below: (by the way, how do you guys post this code in those windows, in the forum? are you just putting it in an html form text box?) <html> <title>title</title> <?php echo '<pre>'; print_r($_POST); echo '</pre>'; if (isset($_POST['submitted'])) { $errors = array(); $item_id = ($_POST['plant_id']); $column2 = ($_POST['column2_id']); if (empty($errors)) { require ('databaseconnect.php'); for ($i=0;$i<count($medicine);$i++) { $query = "INSERT INTO tablename(item_id, column2_id) VALUES ('$item_id', '$column2[$i]')"; $result = mysql_query ($query); } if ($result) { echo 'items have been added'; exit(); } else { echo 'system error. Not added'; echo '<p>' . mysql_error() . '<br><br>query:' . $query . '</p>'; exit(); } mysql_close(); } } ?> <body> <FORM style="border: 1px dotted red; padding: 2px" action="self_formname.php" method="post"> item id field:<br> only enter numbers here<br> //this will be a hidden passed variable in finished form <input type="text" name="item_id" value="<?php if(isset($_POST['item_id'])) echo $_POST['item_id']; ?>" /> <br><br> characteristics:<br> <input type="checkbox" name="column2_id[]" value="1" > one <br> <input type="checkbox" name="column2_id[]" value="2" > two <br> <input type="checkbox" name="column2_id[]" value="3" > three <br> <input type="checkbox" name="column2_id[]" value="4" > four <br> <input type="checkbox" name="column2_id[]" value="5" > five <br> <input type="checkbox" name="column2_id[]" value="6" > six <br> <input type="checkbox" name="column2_id[]" value="7" > Seven <br> </fieldset><br><br> <input type="hidden" name="submitted" value="TRUE"> <input type="submit" /> </form> </body> </html>
-
uh-oh! Doing that, generated this error on reloading of the page: Warning: Invalid argument supplied for foreach() in /filepath/htdocs/filename.php on line 15 Fatal error: Call to undefined function mysql_real_query() in /filepath/htdocs/filename.php on line 18
-
ok, I've done that. It's definitely knows what I've clicked. Still only the first entry goes into the database. Here's what it created. Array ( [item_id] => 20 [column2_id] => Array ( [0] => 1 [1] => 5 [2] => 9 [3] => 10 ) [submitted] => TRUE ) one item has been added
-
hehe! I wish it was that simple. In the actual form, there are several checkboxes and at least half of them were checked.
-
Ok, I tried that. Unfortunately, it's doing the same thing. Only the first row goes into the database. Here's what I wrote: for ($i=0;$i<count($column2);$i++) { $query = "INSERT INTO tablename(item_id, column2_id) VALUES ('$item_id', '$column2[$i]')"; $result = mysql_query ($query); if ($result) { echo 'your items have been added';
-
please please please, somebody help. I'm new at php, and I'm going nuts trying to figure out this one task. In one form, I need to enter the results of two sets of checkboxes into two tables. Nothing has worked, so I'm going back to basics and building from there. I built this code below. It works but only puts the first row in, matching the first checkbox selected. Nothing else Here's the code: <?php if (isset($_POST['submitted'])) { $errors = array(); $item_id = ($_POST['item_id']); $column2 = ($_POST['column2_id']); if (empty($errors)) { require ('databaseConnect.php'); foreach ($_POST['column2_id'] AS $key => $column2) { $query = "INSERT INTO tablename(item_id, column2_id) VALUES ('$item_id', '$column2')"; $result = mysql_query ($query); if ($result) { echo 'one plant has been added'; exit(); } else { echo 'system error. No plant added'; echo '<p>' . mysql_error() . '<br><br>query:' . $query . '</p>'; exit(); } mysql_close(); } } } ?> <body> <FORM action="test.php" method="post"> <input type="text" name="item_id" value="<?php if(isset($_POST['item_id'])) echo $_POST['item_id']; ?>" /> <br> <input type="checkbox" name="column2_id[]" value="1" > one <br> <input type="checkbox" name="column2_id[]" value="2" > two <br> <input type="checkbox" name="column2_id[]" value="3" > three <br> </fieldset><br><br> <input type="hidden" name="submitted" value="TRUE"> <input type="submit" /> </form>
-
ok... Can somebody give me a rundown how to build a form that submits multiple rows to two different tables. I've been trying to write this out and making absolutely no progress. I'm thinking maybe I'll start from scratch if anybody can give a basic rundown of how to do this. Below is essentially what I've got so far. The medical table drops every single checkbox in, whether I checked it or not, and it only puts zeros in the second column. I only want a row created for each thing checked. The edible table is doing nothing. No errors though. Just not dropping anything in. I've tried a dozen different ways of doing this and I've gone cross-eyed. Maybe a clear mind can tell me how to do this. <?php if (isset($_POST['submitted'])) { $errors = array(); $descriptor1 = trim($_POST['plant_id']); $descriptor4 = trim($_POST['alternative']); $descriptor5 = trim($_POST['aromatherapy']); $descriptor6 = trim($_POST['bach']); $descriptor17 = trim($_POST['chocolate_substitute']); $descriptor18 = trim($_POST['coffee_substitute']); $descriptor19 = trim($_POST['coloring']); if (empty($errors)) { require ('3_z_mysq1_c0nn3ct.php'); $query = "INSERT INTO plant_edible_link(plant_id, edible_id) VALUES ('$descriptor1', '$descriptor17'), ('$descriptor1', '$descriptor18'), ('$descriptor1', '$descriptor19'), $result = mysql_query ($query); $query = "INSERT INTO plant_medicine_link(plant_id, medicine_id) VALUES ('$descriptor1', '$descriptor4'), ('$descriptor1', '$descriptor5'), ('$descriptor1', '$descriptor6'), $result = @mysql_query ($query); if ($result) { echo 'one plant has been added'; exit(); } else { echo 'system error. No plant added'; echo '<p>' . mysql_error() . '<br><br>query:' . $query . '</p>'; exit(); } mysql_close(); } else { echo 'error. the following error occured <br>'; foreach ($errors as $msg) { echo " - $msg<br>\n"; } } // end of if } // end of main submit conditional ?> <FORM action="insertMultipletables1f.php" method="post"> <br> Plant relationships, part 2<br> <table bgcolor=#FFEC8B width=590> <tr><td> plant id:<br> only enter numbers here<br> <input type="text" name="plant_id" value="<?php if(isset($_POST['plant_id'])) echo $_POST['plant_id']; ?>" /> <br> Medical Uses:<br> <input type="checkbox" name="alternative" value="1" > Alterative <br> <input type="checkbox" name="aromatherapy" value="2" > Aromatherapy <br> <input type="checkbox" name="bach" value="3" > Bach <br> <br><br> <table bgcolor=#FFEC8B width=590> <tr> <td> Edible Uses:<br> <input type="checkbox" name="chocolate_uses" value="14" > Chocolate substitute<br> <input type="checkbox" name="coffee_substitute" value="24" > Coffee substitute<br> <input type="checkbox" name="coloring" value="34" > Coloring <br> </fieldset><br><br> <input type="hidden" name="submitted" value="TRUE"> <input type="submit" /> </form>
-
One form - multiple entries on two tables... yikes!
turpentyne replied to turpentyne's topic in PHP Coding Help
dang! didn't work. I added the code in with checkboxes for one table, and it's not working. The first table updates, but the second one does nothing. -
One form - multiple entries on two tables... yikes!
turpentyne replied to turpentyne's topic in PHP Coding Help
Hmmm... I might've found the code that will help me. I'll have to plug it in this evening, adapt the form and see if it works. Something like this, maybe: INSERT INTO ''item_characteristics_link'' (''item_id'', [''characteristics_id'']) VALUES (''Item 1'', [''blue'']), (''item 1'', [''circular'']) -
I'm rather new at this, so bear with me if this is obvious and simple. Now that many-to-many databases have sunk into my brain, I'm trying to build a form that puts multiple entries into two different 'link' tables for one item. One for its physical characteristics and one for its uses. Last night I fairly quickly figured out the multiple table entry, by simply duplicating the Insert command.. Trying the same thing to enter into the same table didn't work. Here's a simple test code I've got so far.. The final will probably be check fields for each item that goes into the link table along with its item id. ( I took the code out I'd written to try and go into the same table.) <?php if (isset($_POST['submitted'])) { $errors = array(); //I just add more descriptors here for new characteristics or uses listed in link table $descriptor1 = trim($_POST['item_id']); $descriptor2 = trim($_POST['characteristics_id']); $descriptor3 = trim($_POST['use_id']); if (empty($errors)) { //this is my connection to database require ('3_z_mysq1_c0nn3ct.php'); $query = "INSERT INTO item_characteristics_link(item_id, characteristics_id) VALUES ('$descriptor1', '$descriptor2')"; $result = @mysql_query ($query); //here I go into the second table - the next 5 lines are what I tried duplicating - didn't work. if (isset($_Post['uses_id'])) $query = "INSERT INTO item_uses_link(item_id, uses_id) VALUES ('$descriptor1', '$descriptor3')"; if ($result) { echo 'your info has been added'; exit(); } else { echo 'system error. No item added'; echo '<p>' . mysql_error() . '<br><br>query:' . $query . '</p>'; exit(); } mysql_close(); } else { echo 'error. the following error occured <br>'; foreach ($errors as $msg) { echo " - $msg<br>\n"; } } // end of if } // end of main submit conditional ?> <FORM style="border: 1px dotted red; padding: 2px" action="backToThisSameFile.php" method="post"><fieldset><legend><b>Enter your info here</b></legend> <table bgcolor=#FFEC8B width=590> <tr><td> //in the final form, this will not be a dropdown, but a unique number passed from another form. Item id field:<br><SELECT NAME="item_id" value="<?php if(isset($_POST['item_id'])) echo $_POST['item_id']; ?>" > <OPTION SELECTED VALUE=""> </OPTION> <OPTION VALUE="1">1 <OPTION VALUE="2">2 <OPTION VALUE="3">3 <OPTION VALUE="4">4 <OPTION VALUE="5">5 <OPTION VALUE="6">6 </select><br> </td> <td> //in the final form, this will not be a dropdown, but a series of individual checkboxes/entries characteristics field:<br> <SELECT name="characteristics_id" value="<?php if(isset($_POST['characteristics_id'])) echo $_POST['characteristics_id']; ?>"> <OPTION SELECTED VALUE=""> </OPTION> <OPTION VALUE="1">1 <OPTION VALUE="2">2 <OPTION VALUE="3">3 <OPTION VALUE="4">4 <OPTION VALUE="5">5 <OPTION VALUE="6">6 </select> <br> another item/entry<br> another item/entry </td> </tr></table> <br><br> <table bgcolor=#FFEC8B width=590> <tr> <td> //in the final form, this will not be a dropdown, but a series of individual checkboxes/entries uses field:<br> <SELECT name="uses_id" value="<?php if(isset($_POST['uses_id'])) echo $_POST['uses_id']; ?>"> <OPTION SELECTED VALUE=""> </OPTION> <OPTION VALUE="1">1 <OPTION VALUE="2">2 <OPTION VALUE="3">3 <OPTION VALUE="4">4 <OPTION VALUE="5">5 <OPTION VALUE="6">6 </select> <br> </td> </tr></table> </fieldset><br><br> <input type="hidden" name="submitted" value="TRUE"> <input type="submit" /> </form>
-
how to streamline a potentially huge set of fields
turpentyne replied to turpentyne's topic in MySQL Help
I suspected originally that I had to break it down into tables for each item. Like building the database items to populate a tiered dropdown menu, right? But I'm still not understanding something. The way it is in my brain, even if I break the geographic locations into individual tables, I'd still have an item_table full of integers representing several subcontinents, countries and provinces. I am at work and distracted by other things, so maybe that's why I'm not grasping this. hah! -
how to streamline a potentially huge set of fields
turpentyne replied to turpentyne's topic in MySQL Help
sorry about the smiley face. Didn't expect that. It's supposed to be 8 and ) -
how to streamline a potentially huge set of fields
turpentyne replied to turpentyne's topic in MySQL Help
Here's a quick little sample: a table called geography, with 3 items in it. Item 100 is in parts of the US and Canada, Item 102, different parts of US and Canada, Item 103 in parts of the US and Mexico At this current structure, i would end up with a thousand fields set to true or false, just to cover all locations. Maybe it's that simple, or maybe I'm just thinking too simply about it. CREATE TABLE IF NOT EXISTS `geography` ( `id` smallint(6) NOT NULL auto_increment, `item_id` smallint( NOT NULL, `canada` varchar(100) NOT NULL, `USA` varchar(100) NOT NULL, `Mexico` varchar(100) NOT NULL, `Alaska` varchar(100) NOT NULL, `British Columbia` varchar(100) NOT NULL, `Washington` varchar(100) NOT NULL, `Oregon` varchar(100) NOT NULL, `California` varchar(100) NOT NULL, `Arizona` varchar(100) NOT NULL, `Sonora` varchar(100) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ; INSERT INTO `geography` (`id`, `item_id`, `canada`, `USA`, `Mexico`, `Alaska`, `British Columbia`, `Washington`, `Oregon`, `California`, `Arizona`, `Sonora`) VALUES (1, 101, 'true', 'true', 'false', 'true', 'true', 'false', 'false', 'false', '', ''), (2, 102, 'true', 'true', 'false', 'false', 'true', 'true', 'true', 'false', '', ''), (3, 103, 'false', 'true', 'true', 'false', 'false', 'false', 'false', 'true', 'true', 'true'); -
I'm very new at setting up databases and php. I want set up a table that breaks down where certain items are located. The highest level is continents (7) Next is subcontinents (about 30) from there, countries (200) Then..gasp...departments/states/provinces (hundreds? Thousands?) Where I really run into a problem, is that these items can be in several of these places across the globe, so I'd need fields that were simply true or false. So I started realizing I'd have to create some 2000 fields or so of place locations. egads! At the very least I'd have to make a huge amount of tables with lots of names in them. Is this what I'd have to do to follow the proper normalization? Am I overlooking a much more simple solution? Any ideas? Thanks!
-
Bear with me. I'm extremely new at this. I have a working form that submits data to one table. Then it redirects to a second form, to enter data for a second table. My challenge is that I need one of the fields in that table to match the auto_generated id field in the first table. The way I'm trying to do this, is by sending one unique entered variable from form1 to the header of form2, and then checking table1 for that variable to get the matching ID. This then will be part of form2 as a hidden field. currently I have it as a text field so I can see if it's working, but the text field is empty. Maybe somebody can spot what I've missed. or suggest a better way to do this... (var1 is the variable that I've passed from form one. I tested with just that information, and it did appear in the text box) Here is the code where the problem seems to be, in the hidden field on form2: <FORM action="form2.php" method="post">Enter your data </b> <input type="text" name="id" value=" <?php $var1 = $_GET['var1']; require ('this_is_my_database_connection.php'); $query = 'SELECT id FROM table WHERE second_field = $var1'; $result = @mysql_query ($query); echo $result; ?>" />