使用数据库表中的特定数据行填充表单字段以更新PHP MYSQL

时间:2014-04-15 22:11:51

标签: php mysql

我所拥有的是一个事件表列表,显示团队的事件列表。每行旁边都有一个编辑按钮,单击该按钮可以进入编辑页面,您可以在其中编辑所选事件。然而,当我点击按钮时,我只得到一个空白页面。 iv包括连接文件和索引文件

的index.php

<?php

require('model/connection.php');
require('model/functions.php');

    if (isset($_POST['action'])) {
        $action = $_POST['action'];
    } else if (isset($_GET['action'])) {
        $action = $_GET['action'];
    } else {
        $action = 'root_menu';
    }


    if ($action == 'root_menu') {
        include('homePage.php');
    } else if ($action == 'add_user') {
        $email = $_POST['email'];
        $password = $_POST['password'];
        $last_name = $_POST['last_name'];
        $first_name = $_POST['first_name'];
        $country = $_POST['country'];
        $city_town = $_POST['city_town'];
        $user_type_id = $_POST['user_type_id'];
        add_user($email, $password, $last_name, $first_name, $country, $city_town, $user_type_id);
        $team_manager = get_users();
        include('homePage.php');
    } else if ($action == 'add_team') {
        $name = $_POST['name'];
        $sport = $_POST['sport'];
        $country = $_POST['country'];
        $city_town = $_POST['city_town'];
        $age_profile = $_POST['age_profile'];
        $user_id = $_POST['user_id'];
        add_team($name, $sport, $country, $city_town, $age_profile, $user_id);
        $team_manager = get_teams();
        include('userPage.php');
    } else if ($action == 'add_player') {
        $last_name = $_POST['last_name'];
        $first_name = $_POST['first_name'];
        $dob = $_POST['dob'];
        $position = $_POST['position'];
        $email = $_POST['email'];
        $country = $_POST['country'];
        $city_town = $_POST['city_town'];
        $password = $_POST['password'];
        $team_id = $_POST['team_id'];
        $user_type_id = $_POST['user_type_id'];
        add_player($last_name, $first_name, $dob, $position, $email, $country, $city_town, $password, $team_id, $user_type_id);
        $team_manager = get_players();

        $from = "teammanager0@outlook.com"; // this is the web app's Email address
        $subject = "Welcome to Team Manager";
        $message = "You have been added to a team on our web app TEAM MANAGER!" . "\n\n" . "In order to login to your team please use
          the following details: " . "\n\n" . "Email: " . $email . "\n\n" . "Password: " . $password;
        $headers = "From:" . $from;
        mail($email, $subject, $message, $headers);
        header("location: http://localhost/TeamManager/teamPage.php?id=$team_id");
    } else if ($action == 'add_event') {
        $event_type = $_POST['event_type'];
        $event_desc = $_POST['event_desc'];
        $event_date = $_POST['event_date'];
        $event_start = $_POST['event_start'];
        $event_end = $_POST['event_end'];
        $team_name = $_POST['team_name'];
        $age_profile = $_POST['age_profile'];
        $user_id = $_POST['user_id'];
        $team_id = $_POST['team_id'];
        add_event($event_type, $event_desc, $event_date, $event_start, $event_end, $team_name, $age_profile, $user_id, $team_id);
        $team_manager = get_events();
        header("location: http://localhost/TeamManager/teamPage.php?id=$team_id");
    } else if ($action == 'delete_event') {
        $event_id = $_POST['event_id'];
        delete_event($event_id);
        header("location: http://localhost/TeamManager/userPage.php");
    } else if ($action == 'edit_event_form') {
        $event_id = $_POST('event_id');
        $event = get_event($event_id);
        $event_type = $event['event_type'];
        $event_desc = $event['event_desc'];
        $event_date = $event['event_date'];
        $event_start = $event['event_start'];
        $event_end = $event['event_end'];
        $team_name = $event['team_name'];
        $age_profile = $event['age_profile'];
        $user_id = $event['user_id'];
        $team_id = $event['team_id'];
        include('editEvent.php');
    } 
    ?>

connection.php

<?php

$mysql_hostname = "localhost";
$mysql_user = "brendan";
$mysql_password = "admin";
$mysql_database = "team_manager";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
?>

eventPage.php

<?php
require_once('auth.php');
session_start();
if (trim($_SESSION['SESS_USER_TYPE']) == '2') {
    header("location: playerPage.php");
    exit();
}

require_once('model/connection.php');
require_once('model/deleteEvent.php');
$query = "SELECT * FROM events WHERE user_id = '" . $_SESSION['SESS_USER_ID'] . "'";
$team_manager = mysql_query($query) or die(mysql_error());
?>
<div id="sectionLeft">
    <div class="eventsTable">
        <h3>Events</h3>
        <table>
            <tr>
                <td>Team Name</td>
                <td>Event</td>
                <td>Description</td>
                <td>Date</td>
                <td>Start Time</td>
                <td>End Time</td>
            </tr>
            <?php while ($row = mysql_fetch_assoc($team_manager)) { ?>
                <tr>
                    <td><?php echo $row['team_name']; ?> <?php echo $row['age_profile']; ?></td>
                    <td><?php echo $row['event_type']; ?></td>
                    <td><?php echo $row['event_desc']; ?></td>
                    <td><?php echo $row['event_date']; ?></td>
                    <td><?php echo $row['event_start']; ?></td>
                    <td><?php echo $row['event_end']; ?></td>
                    <td>
                        <form action="index.php" method="post" id="delete_event_button" name="form">
                            <input type="hidden" name="action" value="delete_event"/>
                            <input type="hidden" name="event_id"
                                   value="<?php echo $row['event_id']; ?>" />
                            <input type="submit" value="Delete" />
                        </form>
                    </td>
                    <td>
                        <form action="index.php" method="post" id="edit_event_button" name="form">
                            <input type="hidden" name="action" value="edit_event_form"/>
                            <input type="hidden" name="event_id"
                                   value="<?php echo $row['event_id']; ?>" />
                            <input type="submit" value="Edit" />
                        </form>
                    </td>
                </tr>
            <?php } ?>
        </table>
    </div>
    <br /><br />
</div>

editEvent.php

<?php
require_once('auth.php');
session_start();
if (trim($_SESSION['SESS_USER_TYPE']) == '2') {
    header("location: playerPage.php");
    exit();
}

require_once('model/connection.php');
require_once('model/deleteEvent.php');
$query = "SELECT * FROM events WHERE user_id = '" . $_SESSION['SESS_USER_ID'] . "'";
$team_manager = mysql_query($query) or die(mysql_error());
?>
<div id="sectionLeft">
    <div class="eventsTable">
        <h3>Events</h3>
        <table>
            <tr>
                <td>Team Name</td>
                <td>Event</td>
                <td>Description</td>
                <td>Date</td>
                <td>Start Time</td>
                <td>End Time</td>
            </tr>
            <?php while ($row = mysql_fetch_assoc($team_manager)) { ?>
                <tr>
                    <td><?php echo $row['team_name']; ?> <?php echo $row['age_profile']; ?></td>
                    <td><?php echo $row['event_type']; ?></td>
                    <td><?php echo $row['event_desc']; ?></td>
                    <td><?php echo $row['event_date']; ?></td>
                    <td><?php echo $row['event_start']; ?></td>
                    <td><?php echo $row['event_end']; ?></td>
                    <td>
                        <form action="index.php" method="post" id="delete_event_button" name="form">
                            <input type="hidden" name="action" value="delete_event"/>
                            <input type="hidden" name="event_id"
                                   value="<?php echo $row['event_id']; ?>" />
                            <input type="submit" value="Delete" />
                        </form>
                    </td>
                    <td>
                        <form action="index.php" method="post" id="edit_event_button" name="form">
                            <input type="hidden" name="action" value="edit_event_form"/>
                            <input type="hidden" name="event_id"
                                   value="<?php echo $row['event_id']; ?>" />
                            <input type="submit" value="Edit" />
                        </form>
                    </td>
                </tr>
            <?php } ?>
        </table>
    </div>
    <br /><br />
</div>

从functions.php获取事件功能

function get_event($event_id) {
    global $bd;
    $query = "SELECT * FROM events
              WHERE event_id = '$event_id'";
    $events = $bd->query($query);
    $event = $events->fetch();
    return $event;
}

1 个答案:

答案 0 :(得分:0)

第77行错误的paranthesis - &gt; $event_id = $_POST('event_id'); 需要正方形