0

This is my code which shows current events and lets the user change the date, name or venue of the event.

I keep getting a 500 error for some reason. I think it is due to the information being passed to and from the database.

database set up is :userid ,eventname, venue, date, name ,eventid... respectivley

        <div class="current events">
            <h1>Your Current Events:</h1>
            <?php

            $sql = "SELECT * FROM events WHERE userid='{$_SESSION['u_id']}';";
            $result = mysqli_query($conn, $sql);
            if (mysqli_num_rows($result) > 0){
                while ($row = mysqli_fetch_assoc($result)){
                    echo "<b>Event name: </b>";
                    echo " ";
                    echo $row['eventname'];
                    echo " ";
                    echo "<b>Event Venue: </b>";
                    echo " ";
                    echo $row['venue'];
                    echo " ";
                    echo "<b>Event Date: </b>";
                    echo " ";
                    echo $row['date'];
                    echo "
                        <form method='POST' action='editevent.php'>
                            <input type='hidden' name='eventname' value='" .$row['eventname']. "'>
                            <input type='hidden' name='venue' value='" .$row['venue']. "'>
                            <input type='hidden' name='date' value='" .$row['date']. "'>
                            <input type='hidden' name='name' value='" .$row['name']. "'>
                            <button>Edit</button>

                        </form>


                    ";

                }
            }else{
                echo "No Upcoming Events";
            }

            ?>
        </div>

I then have another file in my includes directory which allows changes to the information.

<?php

    session_start();
    if (isset($_POST['eventsubmit'])) {
        $eventname = $_POST['eventname'];
        $venue = $_POST['venue'];
        $date = $_POST['date'];
        $name = $_POST['name'];

        $eventname = mysqli_real_escape_string($conn, $_POST['eventname']);
        $venue = mysqli_real_escape_string($conn, $_POST['venue']); 
        $date = mysqli_real_escape_string($conn, $_POST['date']); 
        $name = mysqli_real_escape_string($conn, $_POST['name']);   


            $sql = "UPDATE events SET eventname='$eventname' WHERE userid='2' ";
            mysqli_query($conn, $sql);
            header("Location: ../members.php?event=success");
            exit();



    } else {
        header("Location: ../signup.php");
        exit();
    }

}
1
  • 1
    you don't have session_start(); in your first code. Add it and check Commented Oct 7, 2017 at 5:25

2 Answers 2

3

I check your code in second php file you put one extra this } please remove it.

Sign up to request clarification or add additional context in comments.

Comments

0

please use mysqli_error instruction to get exactly which error you get

 mysqli_query($conn, $sql)or die( mysqli_error($conn));

or you can use to show php error if there any error in php syntax in start of page

 error_reporting(E_ALL);
 ini_set('display_errors', 1);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.