1

What i have is an event table list that shows a list of events for a team. beside each row is an edit button that when clicked brings you to an edit page where you can edit that selected event. however when i click the button i get nothing but a blank page. iv included the connection file and the index file

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>

get event function from 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) in the index.php you have `header("location: http://localhost/Tea... ` replace the "http://localhost" with a variable such that if you get the code somewhere else it will be easier to change 2) the white page is most probably a 500 error page, right click the browser and go "inspect element"(firefox) or something like that, this will open a "console" window, go to the "network" tab and refresh the page/click button 500 error -> internal server error ( typo, unable to make connection .. )) – Ţîgan Ion Apr 15 '14 at 22:18
  • also you could try looking [into](http://www.php.net/manual/en/function.error-reporting.php) letting php report all the errors – Ţîgan Ion Apr 15 '14 at 22:22
  • the header("location: http://localhost/... is in a different form action and works fine, the form action in question is edit_event_form. you are right about the 500 error and im not sure how i would go about letting php report the errors ?? –  Apr 15 '14 at 22:29
  • i'm not sure what you use, but you can try add `// Report all PHP errors -> error_reporting(E_ALL); // Report all PHP errors -> error_reporting(-1); // Same as error_reporting(E_ALL); -> ini_set('error_reporting', E_ALL);` before your "fault" code, or just google hot to set the error reporting globally ( it can be the last line of code I've written ) – Ţîgan Ion Apr 15 '14 at 22:37
  • I got this error when i turned on the php error reporting, Fatal error: Array callback has to contain indices 0 and 1 in H:\4thYear\UniServerZ\www\TeamManager\index.php on line 77 –  Apr 15 '14 at 22:54
  • try to use a text editor that shows the code lines , for example sublime text or notepad ++, this will highlight the code and also will show you the line number, this way you will be able to find easier the problem after reading such error reports – Ţîgan Ion Apr 15 '14 at 23:03

1 Answers1

0

line 77 wrong paranthesis -> $event_id = $_POST('event_id'); need square ones

Ţîgan Ion
  • 176
  • 1
  • 12
  • yeah i just got it there thank you ! im getting a new error now(of course) Fatal error: Call to a member function query() on a non-object in H:\4thYear\UniServerZ\www\TeamManager\model\functions.php on line 55, line 55 is $events = $bd->query($query); , any ideas ?? –  Apr 15 '14 at 23:04
  • did you initialize your $bd variabile? – Ţîgan Ion Apr 15 '14 at 23:07
  • also read [this](http://stackoverflow.com/questions/13530465/how-to-declare-a-global-variable-in-php) hope will help you with variables – Ţîgan Ion Apr 15 '14 at 23:11
  • yes in connection.php, and then set it as a global variable in the function –  Apr 15 '14 at 23:12
  • you can't set it from the function as global, you have to set it in the connection.php as global, but you can include your connection.php file and use the variable from this context already – Ţîgan Ion Apr 15 '14 at 23:15
  • I tried what you suggested but it didnt work, thank you for helping! –  Apr 15 '14 at 23:34