Birdmansplace Posted May 10, 2015 Share Posted May 10, 2015 I am makeing a simple web page for my horse arena where when a rider registers there name and horse i can also select what event they are taking part in wheather is 1 type of event or every event. I have wording code that that submits there name and horse but i want to add checkboxs for the different events and once checked and submited not only will it enter name and horse in a main table but also in a table for that event. I am doing this so i can create lists for each event and have a master list and from those lists i plan on being able to edit entrys to add times and other info. heres my code so far. Thanks for taking the time to help me out <?php ini_set("display_errors", "10"); error_reporting(E_ALL); if (isset($_POST['submit'])) { { //YOU NEED TO HAVE AN EXTERNAL PHP FILE WITH YOUR DATABASE CONNECTION DETAILS. LET ME KNOW IF YOU DON'T KNOW HOW include("dbinfo.php"); mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to establish a connection to the relevant database."); $ename = mysql_real_escape_string($_POST['ename']); $ehorse = mysql_real_escape_string($_POST['ehorse']); $ipaddress = getenv('REMOTE_ADDR'); $now_datetime = date('Y-m-d h:i:s'); $msg = "$ename has been saved !"; $query = "INSERT INTO register VALUES ('','$ename','$ehorse','$ipaddress',NOW()) "; mysql_query($query); echo "<br />"; echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>"; echo "<br /><br /><br /><br />"; echo "<a href='register.php'><input name='' type='button' value='Add Another'/>"; echo "<br />"; echo "<br />"; echo "<a href='reglist.php'><input name='' type='button' value='View List'/>"; exit(); } } ?> <br /> <br /> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> Name:<input type="text" name="ename" value="<?php if (isset($_POST['ename'])) echo $_POST['ename']; ?>" size="50"/> <br /> <br /> Horse name: <input type="text" name="ehorse" value="<?php if (isset($_POST['ehorse'])) echo $_POST['ehorse']; ?>" size="45"> <br /> <br /> <-- here is where i would like checkboxs--> <input name"barrels" type="checkbox" value=""/> i want if check to add ename and ehorse to a table named barrels if not skip and go to next one <input name"roping" type="checkbox" value=""/> and this one if checked just like above, but to a table named roping <input type="submit" name="submit" id="submit" value="Submit Details"> <input type="reset" name="reset" id="reset" value="Reset Form"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/296172-register-form-to-mutil-sql-tables/ Share on other sites More sharing options...
Barand Posted May 10, 2015 Share Posted May 10, 2015 Reading your post it seems as though an owner can register one or more horses a horse can enter one or more types of event So your table structure would be owner +----------+-------------------+ | owner_id | owner_name | +----------+-------------------+ | 101 | Roy Rogers | | 102 | Lone Ranger | +----------+-------------------+ | | +-----------+ | horse | event +----------+----------+-------------------+ +---------+------------+ | owner_id | horse_id | horse_name | | type | name | +----------+----------+-------------------+ +---------+------------+ | 101 | 1 | Trigger | | 1 | Barrel | | 102 | 2 | Silver | | 2 | Roping | | 102 | 3 | Flicka | +---------+------------+ +----------+----------+-------------------+ | | | | | +----------+ +----------------+ | | entry | | +----------+----------+--------+ | id | horse_id | event | +----------+----------+--------+ | 1 | 1 | 1 | | 2 | 1 | 2 | | 3 | 2 | 1 | | 4 | 3 | 2 | +----------+----------+--------+ So the processing for the form would be as follows Check if owner id is stored in session If notAdd record to the owner table Get id of new owner using mysqli_insert_id() store in session Add horse to horse table using owner id Get id of new horse Add record/s to entry table using horse id NOTE: mysql_ functions are deprecated and you should be using mysqli or PDO functions Quote Link to comment https://forums.phpfreaks.com/topic/296172-register-form-to-mutil-sql-tables/#findComment-1511298 Share on other sites More sharing options...
Birdmansplace Posted May 10, 2015 Author Share Posted May 10, 2015 I think i understand what your saying but I have no clue how to go about it. The code i use i made for one thing and it just gets copied and pasted and changed for what i need. I don't know much about php other than to put basic forms into data base and pull it out. I am one of those i find the code make a test database and see how it works. Iike if/else php statement took me like 3 hours to figure it just the basic function to dispay info based on wheather or not any data was saved for that feild. I hate to ask but i would need to see the code to totally understand what your talking about and how it would work. I want to beable to click submit once and everything gets placed where it needs to. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/296172-register-form-to-mutil-sql-tables/#findComment-1511329 Share on other sites More sharing options...
Barand Posted May 10, 2015 Share Posted May 10, 2015 I hate to ask but i would need to see the code to totally understand what your talking about . that's what the examples in the manual are for Quote Link to comment https://forums.phpfreaks.com/topic/296172-register-form-to-mutil-sql-tables/#findComment-1511341 Share on other sites More sharing options...
Solution Birdmansplace Posted May 12, 2015 Author Solution Share Posted May 12, 2015 Thanks for the help. Managed to get my form to write to different tables even though i am write the same info to each one. I just setup a html list menu to give option yes or no for the event field and used a if statement to not list the No people in a table. Quote Link to comment https://forums.phpfreaks.com/topic/296172-register-form-to-mutil-sql-tables/#findComment-1511509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.