Note that there are some explanatory texts on larger screens.

plurals
  1. POEdit SQL with dropdown
    primarykey
    data
    text
    <p>So just like always, I'm working on code that up until now I have had no experience with. </p> <p>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.</p> <p>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.</p> <pre><code>&lt;?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&lt;$count;$i++){ $del_id = $checkbox[$i]; $sql ="DELETE FROM persons WHERE PID='$del_id'"; $result = mysql_query($sql);} if($result){ echo "&lt;meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\"&gt;";} } $query = "Select * FROM persons"; $result = mysqli_query($con, $query); $num=mysqli_num_rows($result); echo $id; echo $action; ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; tr:nth-child(even) { background-color:#00fff0; } &lt;/style&gt; &lt;script&gt; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;table id="persons" name="persons" border="0" cellpadding="1"&gt; &lt;form name="database" action="viewtable.php" type="post"&gt; &lt;div type="hidden" class="pidmessage" style="display:none;"&gt;Unique Identifier&lt;/div&gt; &lt;div type="hidden" class="fnamemessage" style="display:none;"&gt;Contact's First Name&lt;/div&gt; &lt;div type="hidden" class="lnamemessage" style="display:none;"&gt;Contact's Last Name&lt;/div&gt; &lt;div type="hidden" class="emailmessage" style="display:none;"&gt;Contact's Email Address&lt;/div&gt; &lt;div type="hidden" class="phonemessage" style="display:none;"&gt;Contact's Home Phone Number&lt;/div&gt; &lt;div type="hidden" class="cellmessage" style="display:none;"&gt;Contact's Mobile Phone Number&lt;/div&gt; &lt;div type="hidden" class="campusmessage" style="display:none;"&gt;Is the contact interested in residential or online courses?&lt;/div&gt; &lt;div type="hidden" class="statemessage" style="display:none;"&gt;Contact's Home State&lt;/div&gt; &lt;div type="hidden" class="studenttypemessage" style="display:none;"&gt;The contact is interested in enrolling as this&lt;/div&gt; &lt;div type="hidden" class="termmessage" style="display:none;"&gt;The contact is interested in enrolling beginning this term&lt;/div&gt; &lt;div type="hidden" class="enrollmentmessage" style="display:none;"&gt;The contact is interested in enrolling in this many credit hours&lt;/div&gt; &lt;div type="hidden" class="degreemessage" style="display:none;"&gt;The contact is interested in pursuing this type of degree&lt;/div&gt; &lt;div type="hidden" class="messagemessage" style="display:none;"&gt;The contact heard about TTU in this manner&lt;/div&gt; &lt;div type="hidden" class="commentsmessage" style="display:none;"&gt;These are comments the contact left&lt;/div&gt; &lt;?php $i = 0; $data = array(); while($row = mysqli_fetch_assoc($result)) { $data[] = $row; } $colNames = array_keys(reset($data)); ?&gt; &lt;tr&gt;&lt;th&gt;&amp;nbsp;&lt;/th&gt; &lt;?php foreach($colNames as $colName) { echo"&lt;th class='{$colName}'&gt;$colName&lt;/th&gt;"; } ?&gt; &lt;/tr&gt; &lt;?php foreach($data as $row) { echo "&lt;tr&gt;"; echo "&lt;td&gt;&lt;input type='checkbox' name='checkbox[]' value='{$row['PID']}'&gt;&lt;/input&gt;&lt;/td&gt;"; foreach($colNames as $colName) { echo "&lt;td&gt;".$row[$colName]."&lt;/td&gt;"; } echo"&lt;/tr&gt;"; } ?&gt; &lt;tr class="clear"&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td colspan="7"&gt; &lt;select name="action"&gt; &lt;option value=""&gt;--Select One--&lt;/option&gt; &lt;option value="delete"&gt;Delete Entry&lt;/option&gt; &lt;option value="assign"&gt;Assign&lt;/option&gt; &lt;option value="contacted"&gt;Move to contacted&lt;/option&gt; &lt;option value="edit"&gt;Edit&lt;/option&gt; &lt;option value=""&gt;Cancel&lt;/option&gt; &lt;/select&gt;&lt;/td&gt; &lt;td colspan="7"&gt; &lt;input type="submit" name="submit" value="Submit"&gt; &lt;/input&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/form&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php mysqli_close($con); ?&gt; </code></pre> <p>Note: The todo list that is commented out on top is on the list of things (clearly) todo...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload