0

所以就像往常一样,我正在编写迄今为止我没有经验的代码。

我要做的是为工作中的一个部门创建一个票据类型系统,用于联系潜在的学生。大多数情况下,我对 HTML 和 PHP 没问题,它正在学习让我难过的 SQL。我什至不确定这一切是否正确。我可能还需要合并 AJAX。基本上,联系人将填写一份表格,其中包含他们想要攻读的学位类型以及联系信息等信息……一切都很好地插入到 SQL 中,但是当我想从我的 viewtable.php 页面编辑它时问题就来了.

这只是工作原型,最终它将有用户登录和其他类似的东西,以及管理控制台等......所以事不宜迟,这是我的可视化代码。如果不够,请告诉我。我会继续研究,但你们可以提供的任何帮助将不胜感激。

<?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>&nbsp;</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>&nbsp;</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);
?>

注意:顶部被注释掉的待办事项列表是(明确)待办事项列表...

4

1 回答 1

0

到目前为止,我所看到的这一部分:

for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql ="DELETE FROM persons WHERE PID='$del_id'";
$result = mysql_query($sql);}

我没有看到 $count 的声明位置,也没有看到 $checkbox。如果 $checkbox 是一个数组,你从哪里得到它?

否则,只要您熟悉 jQuery,从 ajax 进行这项工作就不难了。只需将更新的代码剪切到它自己的 php 文件中,然后让 jQuery 通过 ajax 将表单值传递给新脚本。

于 2013-05-17T21:18:05.783 回答