Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
<?php
if (!mysqli_connect_errno($con)) {

    $queryStr = "SELECT * " .
            "FROM crewlist";
}
$result = mysqli_query($con, $queryStr);
while ($row = mysqli_fetch_array($result)) {

    echo "<tr>.<th>" . $row["crew_name"] . "<br></br>" . "</th>";
    echo "<th>" . $row["crew_rank"] . "</th>";
    echo "<th>" . $row["start_date"] . "</th>";
    echo "<th>" . $row["end_date"] . "</th>";
    echo "<th>" . $row["watchkeeping"] . "</th>";
    echo "<th>" . $row["active"] . "</th>";
    echo "<td><a href="editcrew.php?id=" . $row['crew_id'] . "">Edit</a>";

    echo "<td><a href="delete.php?id=" . $row['crew_id'] . "">Delete</a>";
}
?>

editcrew.php

<table>
    <form action="handlecrewedit.php" method="post">
        <tr>
            <td>Crew Name:</td>
            <td><input type="text" name="CrewName" id ="CrewName"required></td>     
        </tr>
        <tr>
            <td>Crew Rank:</td>
            <td><input type="text" name="CrewRank" id="CrewRank" required></td>     
        </tr>
        <tr>
            <td>Start Date:</td>
            <td><input type="text" name="StartDate" id="StartDate" required></td>       
        </tr>
        <tr>
            <td>End Date:</td>
            <td><input type="text" name="EndDate" id="EndDate" required></td>       
        </tr>
        <tr>
            <td>Payroll No:</td>
            <td><input type="text" name="PayrollNo" id="PayrollNo" required></td>       
        </tr>
        <tr>
            <td>Employee No:</td>
            <td><input type="text" name="EmployeeNo" id="EmployeeNo" required></td>     
        </tr>
        <tr>
            <td>Watching Keeping:</td>
            <td><input type="text" name="WatchKeeping" id="WatchKeeping" required></td>     
        </tr>
        <tr>
            <td>Active:</td>
            <td><input type="text" name="Active" id="Active" required></td>     
        </tr>
        <tr>
            <td><input type="submit" value="Submit" ></td>


        </tr>
    </form>
</table>

handlecrewedit.php

<?php

require 'dbfunction.php';
$con = getDbConnect();
$crew_id = $_POST["crew_id"];
$CrewName = $_POST["CrewName"];
$CrewRank = $_POST["CrewRank"];
$StartDate = $_POST["StartDate"];
$EndDate = $_POST["EndDate"];
$PayrollNo = $_POST["PayrollNo"];
$EmployeeNo = $_POST["EmployeeNo"];
$WatchKeeping = $_POST["WatchKeeping"];
$Active = $_POST["Active"];


if (!mysqli_connect_errno($con)) {

$queryStr = "SELECT crew_id " .
        "FROM crewlist"; 
}
$result = mysqli_query($con, $queryStr);
while ($row = mysqli_fetch_array($result)) {        



if (!mysqli_connect_errno($con)) {
    $sqlQueryStr = "UPDATE crewlist SET crew_name = '$CrewName', crew_rank = '$CrewRank', start_date = '$StartDate' "
            . ", end_date = '$EndDate', payroll_no = '$PayrollNo'"
            . ", employee_no = '$EmployeeNo', watchkeeping = '$WatchKeeping', active = '$Active' WHERE crew_id = " . $row['crew_id'] . "";


    }
    mysqli_query($con, $sqlQueryStr);
    header('Location: crewlisting.php');
    mysqli_close($con);
}




mysqli_close($con);
?>

This is another issue on my modifying entries. I'm not quite sure if I can simply copy and paste my delete code for my edit code, but here is some rough gauge of my table. Unlike the delete function, by selecting the edit function, it directs the user to the form page and it requires them to fill in the updated data.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
176 views
Welcome To Ask or Share your Answers For Others

1 Answer

Replace editcrew.php and handlecrewedit.php file code with below code.

editcrew.php

<table>
    <form action="handlecrewedit.php" method="post">
        <input type="hidden" name="crew_id" value="<?php echo $_GET['id']; ?>" />
        <tr>
            <td>Crew Name:</td>
            <td><input type="text" name="CrewName" id ="CrewName"required></td>     
        </tr>
        <tr>
            <td>Crew Rank:</td>
            <td><input type="text" name="CrewRank" id="CrewRank" required></td>     
        </tr>
        <tr>
            <td>Start Date:</td>
            <td><input type="text" name="StartDate" id="StartDate" required></td>       
        </tr>
        <tr>
            <td>End Date:</td>
            <td><input type="text" name="EndDate" id="EndDate" required></td>       
        </tr>
        <tr>
            <td>Payroll No:</td>
            <td><input type="text" name="PayrollNo" id="PayrollNo" required></td>       
        </tr>
        <tr>
            <td>Employee No:</td>
            <td><input type="text" name="EmployeeNo" id="EmployeeNo" required></td>     
        </tr>
        <tr>
            <td>Watching Keeping:</td>
            <td><input type="text" name="WatchKeeping" id="WatchKeeping" required></td>     
        </tr>
        <tr>
            <td>Active:</td>
            <td><input type="text" name="Active" id="Active" required></td>     
        </tr>
        <tr>
            <td><input type="submit" value="Submit" ></td>


        </tr>
    </form>
</table>

handlecrewedit.php

<?php
require 'dbfunction.php';
$con = getDbConnect();
$crew_id = $_POST["crew_id"];
$CrewName = $_POST["CrewName"];
$CrewRank = $_POST["CrewRank"];
$StartDate = $_POST["StartDate"];
$EndDate = $_POST["EndDate"];
$PayrollNo = $_POST["PayrollNo"];
$EmployeeNo = $_POST["EmployeeNo"];
$WatchKeeping = $_POST["WatchKeeping"];
$Active = $_POST["Active"];

if (!mysqli_connect_errno($con)) {
    $sqlQueryStr = "UPDATE crewlist SET crew_name = '$CrewName', crew_rank = '$CrewRank', start_date = '$StartDate' "
            . ", end_date = '$EndDate', payroll_no = '$PayrollNo'"
            . ", employee_no = '$EmployeeNo', watchkeeping = '$WatchKeeping', active = '$Active' WHERE crew_id = " . $crew_id . "";
    mysqli_query($con, $sqlQueryStr);
}
header('Location: crewlisting.php');
mysqli_close($con);
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...