Search the Community
Showing results for tags 'create_table'.
-
Hello, I am creating a form for an administrator to fill in USER information. So far, I have a database in MySQL that has a USER table, with a user_type field and two user_type tables: STUDENT_USER and FACULTY_USER. I am setting up a drop-down list for the administrator to select whether the new USER is a "student" or "faculty." When they select either one and submit the application to log in, I want the database to automatically create a new, child table of the selected type with a foreign key of user_id from the parent USER table. What is a query I can use to create a related table based on a newly created USER? How do I start coding this? Are there easier options I have? so far, my php code for the add, update, delete form: <html> <head> </head> <body> <?php $connect = mysql_connect('localhost', 'root', ''); if (!$connect){ die("Cannot connect: " . mysql_error()); } mysql_select_db('honors thesis', $connect); if(isset($_POST['update'])){ $UpdateQuery = "UPDATE honor student SET student_id='$_POST[studentID]', user_id='$_POST[userName]', password='$_POST[passWord]', user_type='$_POST[userType]', last_name='$_POST[lastName]', first_name='$_POST[firstName]', address='$_POST[addRess]', phone='$_POST[pHone]', email='$_POST', committee_num='$_POST[committeeNum]', degree_program='$_POST[degreeProgram]' WHERE user_id='$_POST[hidden]'"; mysql_query($UpdateQuery, $connect); }; if(isset($_POST['delete'])){ $DeleteQuery = "DELETE FROM honor student WHERE user_id='$_POST[hidden]'"; mysql_query($DeleteQuery, $connect); }; if(isset($_POST['add'])){ $AddQuery = "INSERT INTO honor student (user_id, user_name, password, user_type, last_name, first_name, address, phone, email, committee_num, degree_program) VALUES ('$_POST[uuserID]', '$_POST[uuserName]', '$_POST[upassWord]', '$_POST[uuserType]', '$_POST[ulastName]', '$_POST[ufirstName]', '$_POST[uaddRess]', '$_POST[upHone]', '$_POST[ueMail]', '$_POST[ucommitteeNum]', '$_POST[udegreeProgram]')"; mysql_query($AddQuery, $connect); }; $sql = "SELECT * FROM honor student"; $myUsers = mysql_query($sql, $connect); echo "<table border=1> <tr> <th>User ID</th> <th>User Name</th> <th>Password</th> <th>User Type</th> <th>Last Name</th> <th>First Name</th> <th>Address</th> <th>Phone</th> <th>Email</th> <th>Committee Number</th> <th>Degree Program</th> </tr>"; while($userRecord = mysql_fetch_array($myUsers)){ echo "<form action=index.php method=post>"; echo "<tr>"; echo "<td>" . "<input type=text name=userID value='{$userRecord['user_id']}'>" . " </td>"; echo "<td>" . "<input type=text name=userName value='{$userRecord['user_name']}'>" . " </td>"; echo "<td>" . "<input type=text name=passWord value='{$userRecord['password']}'>" . " </td>"; echo "<td>" . "<input type=text name=userType value='{$userRecord['user_type']}'>" . " </td>"; echo "<td>" . "<input type=text name=lastName value='{$userRecord['last_name']}'>" . " </td>"; echo "<td>" . "<input type=text name=firstName value='{$userRecord['first_name']}'>" . " </td>"; echo "<td>" . "<input type=text name=addRess value='{$userRecord['address']}'>" . " </td>"; echo "<td>" . "<input type=text name=pHone value='{$userRecord['phone']}'>" . " </td>"; echo "<td>" . "<input type=text name=eMail value='{$userRecord['email']}'>" . " </td>"; echo "<td>" . "<input type=text name=committeeNum value='{$userRecord['committee_num']}'>" . " </td>"; echo "<td>" . "<input type=text name=degreeProgram value='{$userRecord['degree_program']}'>" . " </td>"; echo "<td>" . "<input type=hidden name=hidden value='{$userRecord['user_id']}'>" . " </td>"; echo "<td>" . "<input type=submit name=update value=update" . " </td>"; echo "<td>" . "<input type=submit name=delete value=delete" . " </td>"; echo "</tr>"; echo "</form>"; } echo "<form action=index.php method=post>"; echo "<tr>"; echo "<td><input type=text name=uuserID></td>"; echo "<td>" . "<input type=text name=uuserName></td>"; echo "<td>" . "<input type=text name=upassWord></td>"; echo "<td>" . "<input type=text name=uuserType></td>"; echo "<td>" . "<input type=text name=ulastName></td>"; echo "<td>" . "<input type=text name=ufirstName></td>"; echo "<td>" . "<input type=text name=uaddRess></td>"; echo "<td>" . "<input type=text name=upHone></td>"; echo "<td>" . "<input type=text name=ueMail></td>"; echo "<td>" . "<input type=text name=ucommitteeNum></td>"; echo "<td>" . "<input type=text name=udegreeProgram></td>"; echo "<td>" . "<input type=submit name=add value=add" . " </td>"; echo "</form>"; echo"</table>"; mysql_close($connect); ?> </body> </html>