Search code examples
phpmysqlparse-error

Getting Error Parse error: syntax error, unexpected '$_GET' (T_VARIABLE)


I am making a page where on page 1 i am fetching data from mysql & on click of the name i am redirecting to another page i.e page 2 where complete details is shown. Please Help ! Here is the php code of Page 1

            $host="localhost"; // Host name 
            $username="root"; // Mysql username 
            $password=""; // Mysql password 
            $db_name="testmra"; // Database name 
            // Connect to server and select databse.
            $conn=mysqli_connect($host,$username,$password) or die("cannot connect"); 
            mysqli_select_db($conn,$db_name);
            $result = mysqli_query($conn,"SELECT name,COUNT(status_id) AS Count from bookingdetails WHERE  YEAR(date) = YEAR(CURDATE()) AND MONTH(date) = MONTH(CURDATE()) AND status_id='2' GROUP BY name");
            echo "<table border='1' style='border:black;'>
                <tr>
                    <!--<th id='td'>Sr No.</th>-->
                    <th id='td'>Name</th>   
                    <th id='td'>No. of Bookings Done</th>
                </tr>";
            while($row = mysqli_fetch_array($result))
            {
                echo "<tr>";

                        echo "<td align='center' id='td'><a href='Details.php'>" . $row['name'] . "</a></td>";
                        echo "<td align='center' id='td'>" . $row['Count'] . "</td>";
                echo "</tr>";
            }
            echo "</table>";
            mysqli_close($conn);
        ?>

Page 2 
<?php

            $host="localhost"; // Host name 
            $username="root"; // Mysql username 
            $password=""; // Mysql password 
            $db_name="testmra"; // Database name 
            // Connect to server and select databse.
            $conn=mysqli_connect($host,$username,$password) or die("cannot connect"); 
            mysqli_select_db($conn,$db_name);
            $name=(varchar) $_GET['name'];
            $result = mysqli_query($conn,"SELECT * from bookingdetails WHERE  YEAR(date) = YEAR(CURDATE()) AND MONTH(date) = MONTH(CURDATE()) AND status_id='2' AND name='$name'");
            echo "<table border='1' style='border:black;'>
                <tr>
                    <th id='td'>Room</th>   
                    <th id='td'>Name</th>
                    <th id='td'>Purpose</th>
                    <th id='td'>Attendee</th>
                    <th id='td'>Date</th>
                    <th id='td'>Start Time</th>
                    <th id='td'>End Time</th>
                </tr>";
            while($row = mysqli_fetch_array($result))
            {
                echo "<tr>";

                        echo "<td align='center' id='td'>" . $row['room'] . "</td>";
                        echo "<td align='center' id='td'>" . $row['name'] . "</td>";
                        echo "<td align='center' id='td'>" . $row['purpose'] . "</td>";
                        echo "<td align='center' id='td'>" . $row['attendee'] . "</td>";
                        echo "<td align='center' id='td'>" . $row['date'] . "</td>";
                        echo "<td align='center' id='td'>" . $row['starttime'] . "</td>";
                        echo "<td align='center' id='td'>" . $row['endtime'] . "</td>";
                echo "</tr>";
            }
            echo "</table>";
            mysqli_close($conn);
        ?> 

Solution

  • change this following line in page1

     echo "<td align='center' id='td'><a href='Details.php'>" . $row['name'] . "</a></td>";
    

    to

     echo "<td align='center' id='td'><a href='Details.php?name=" . $row['name'] . "'>" . $row['name'] . "</a></td>";
    

    and in page 2

    (varchar) $_GET['name']
    

    to

    $_GET['name']