So just like always, I'm working on code that up until now I have had no experience with.
What I'm trying to do is create a ticket type system for a department here at work to use to contact potential students. I'm ok with the HTML and PHP for the most part, it's learning the SQL that has me stumped. I'm really not even sure if it's all being done right. I may need to incorporate AJAX as well. Basically, the contact will fill out a form with information about what type of degree they want to pursue, and contact info etc... Everything inserts fine into the SQL but the problem comes when I want to edit it from my viewtable.php page.
This is just the working prototype, eventually it will have user login and other such things, as well as admin console, etc... so without further ado, here is my viewtable code. If it's insufficient, please let me know. I'll keep researching but any help you guys can offer would be appreciated.
<?php
session_start();
//Must be called before any code or white space is executed
/*
TODO:
1: Get checkboxes to load and display only what was posted via checkboxes from a previously loaded page
2: Cleanup
3: Hover messages for table headers
4: Program search bar
5: Get dropdown to do something
6: Program to only show 10 entries at a time, and be able to move to the next ten entries
7: program to be able to sort by "Last Name" , "First Name", etc...
8: Move database info to a called file for security and ease of access.
*/
$action=$_POST['action'];
$id=array($_POST['id']);
//Create Connection
$con = mysqli_connect("localhost","username","password","database");
//Check Connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else {
//echo "Connection Successful! \n";
}
//If the action dropdown was set
if($action = 'delete') {
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql ="DELETE FROM persons WHERE PID='$del_id'";
$result = mysql_query($sql);}
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">";}
}
$query = "Select * FROM persons";
$result = mysqli_query($con, $query);
$num=mysqli_num_rows($result);
echo $id;
echo $action;
?>
<!DOCTYPE html>
<html>
<head>
<style>
tr:nth-child(even) {
background-color:#00fff0;
}
</style>
<script>
</script>
</head>
<body>
<table id="persons" name="persons" border="0" cellpadding="1">
<form name="database" action="viewtable.php" type="post">
<div type="hidden" class="pidmessage" style="display:none;">Unique Identifier</div>
<div type="hidden" class="fnamemessage" style="display:none;">Contact's First Name</div>
<div type="hidden" class="lnamemessage" style="display:none;">Contact's Last Name</div>
<div type="hidden" class="emailmessage" style="display:none;">Contact's Email Address</div>
<div type="hidden" class="phonemessage" style="display:none;">Contact's Home Phone Number</div>
<div type="hidden" class="cellmessage" style="display:none;">Contact's Mobile Phone Number</div>
<div type="hidden" class="campusmessage" style="display:none;">Is the contact interested in residential or online courses?</div>
<div type="hidden" class="statemessage" style="display:none;">Contact's Home State</div>
<div type="hidden" class="studenttypemessage" style="display:none;">The contact is interested in enrolling as this</div>
<div type="hidden" class="termmessage" style="display:none;">The contact is interested in enrolling beginning this term</div>
<div type="hidden" class="enrollmentmessage" style="display:none;">The contact is interested in enrolling in this many credit hours</div>
<div type="hidden" class="degreemessage" style="display:none;">The contact is interested in pursuing this type of degree</div>
<div type="hidden" class="messagemessage" style="display:none;">The contact heard about TTU in this manner</div>
<div type="hidden" class="commentsmessage" style="display:none;">These are comments the contact left</div>
<?php
$i = 0;
$data = array();
while($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
$colNames = array_keys(reset($data));
?>
<tr><th> </th>
<?php
foreach($colNames as $colName)
{
echo"<th class='{$colName}'>$colName</th>";
}
?>
</tr>
<?php
foreach($data as $row)
{
echo "<tr>";
echo "<td><input type='checkbox' name='checkbox[]' value='{$row['PID']}'></input></td>";
foreach($colNames as $colName)
{
echo "<td>".$row[$colName]."</td>";
}
echo"</tr>";
}
?>
<tr class="clear"><td> </td><td colspan="7">
<select name="action">
<option value="">--Select One--</option>
<option value="delete">Delete Entry</option>
<option value="assign">Assign</option>
<option value="contacted">Move to contacted</option>
<option value="edit">Edit</option>
<option value="">Cancel</option>
</select></td>
<td colspan="7">
<input type="submit" name="submit" value="Submit"> </input></td></tr>
</form>
</table>
</body>
</html>
<?php
mysqli_close($con);
?>
Note: The todo list that is commented out on top is on the list of things (clearly) todo...