How to make a dynamic dropdown box send corresponding ID to the database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • reedma1
    New Member
    • Apr 2015
    • 1

    How to make a dynamic dropdown box send corresponding ID to the database

    I have a table called FACULTY that has FacultyID, FName, and LName in it. That table is prepopulated with information. I can use a dynamic dropdown to get those values to show up on the page.

    MY ISSUE: I also have a publication table that is being connected to each faculty. I want to be able to select multiple faculty and send those ID's (in individual rows) to the faculty publication table. I want the publication information being entered to go into publication table and then the id that is autogenerated from that to also go into the facultypublicat ion table.

    Table names: FACULTY, PUBLICATION, FACULTYPUBLICAT IONS

    MY coding:

    Code:
        
        
            <?php
            	include_once 'dbc.php';
            	function connect() {
            	  mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect to database'.mysql_error());
            	mysql_select_db(DB_NAME);
            	}
            	
            	function close() {
            	mysql_close();
            	}
            
            	function query() {
            	$myData = mysql_query("SELECT * FROM FACULTY");
            	while($record = mysql_fetch_array($myData)) {
            	  echo '<option value="'. $record['FName'] .$record['LName']. '">' . $record['FName'] .' '. $record['LName'] . ' </option>';
            	}
            }
        
        
        <?php
        	include_once 'pullDataR2.php';
        	connect();
        ?>
        
            <!DOCTYPE html>
            
            <head>
            <link href="styles.css" rel="stylesheet">
            <h1> help </h1>
            </head>
            <body>
            
            <div class="StyleDiv" > 
            <!-- coding for journal -->
            <form id="form1" name="form1" method="post" action="RR2.php">
            
            <label for="FName">Faculty Name</label>
            <select multiple="multiple" name="select" id="Faculty">
            <?php query() ?>
            </select>
            <?php close()?>
            <br class="clear" />
            
            <input type="hidden" name="JournalID" id="JournalID" class="textbox" />
            <br class="clear" /> 
            <label for="JournalName">Journal Name</label><input type="text" name="JournalName" id="JournalName" />
            <br class="clear" /> 
            <label for="Rating">Journal Rating</label><select name="Rating" id="Rating">
            <option value="A+">A+</option>
            <option value="A">A</option>
            <option value="A-">A-</option>
            <option value="B+">B+</option>
            <option value="B">B</option>
            <option value="B-">B-</option>
            <option value="C+">C+</option>
            <option value="C">C</option>
            <option value="C-">C-</option>
            <option value="D+">D+</option>
            <option value="D">D</option>
            <option value="D-">D-</option>
            <option value="F">F</option>
            </select>
            <br class="clear" />
            <!-- coding for publication --> 
            <input type="hidden" name="PubID" id="PubID" />
            <br class="clear" /> 
            <label for="Title">Publication Title</label><input type="text" name="Title" id="Title" />
            <br class="clear" /> 
            <label for="Year">Year</label><input type="text" name="Year" id="Year" />
            <br class="clear" /> 
            <label for="Volume">Volume</label><input type="text" name="Volume" id="Volume" />
            <br class="clear" /> 
            <label for="Issue">Issue</label><input type="text" name="Issue" id="Issue" />
            <br class="clear" /> 
            <label for="Comments">Comments</label><textarea name="Comments" id="Comments" cols="45" rows="5"></textarea>
            <br class="clear" /> 
            
            
            
            <input type="submit" name="Submit" id="Submit" value="Submit" />
            <br class="clear" /> 
            </br>
            </br>
            
            </div>
            </form>
            
            <?php
            
            
            //Post Parameters 
            $JournalName = $_POST['JournalName'];  
            $Rating = $_POST['Rating'];
            
            
            $Year = $_POST['Year'];  
            $Comments = $_POST['Comments'];  
            $Volume = $_POST['Volume'];  
            $Issue = $_POST['Issue'];  
            $Title = $_POST['Title'];
            
            
            
            //create connection
            $conn = new mysqli('localhost','root','isasurvey','isasurvey');
            	if($conn->connect_errno) {
                    echo 'failure</br>';
            	}
            
            
            //Query 
            
             //INSERT 
             $stmt = $conn->prepare (" INSERT INTO JOURNAL ( JournalName, Rating )  VALUES ( '$JournalName', '$Rating' )"); 
             $stmt->bind_param("sssssss", $JournalName, $Rating);
             $stmt->execute();
             
            
             //INSERT 
             $stmt = $conn->prepare(" INSERT INTO PUBLICATION ( Year, Comments, Volume, Issue, Title )  VALUES ( '$Year', '$Comments', '$Volume', '$Issue', '$Title' )"); 
             $stmt->bind_param("sssssss", $Year, $Comments, $Volume, $Issue, $Title);
             $stmt->execute(); 
            
            
            ?>
            
            </body>
            </html>
    Last edited by reedma1; Apr 5 '15, 02:50 PM. Reason: Format coding
Working...