Jump to content

MySQLi view script


arjanvr

Recommended Posts

I have this script working fine in a dir on my website but now I need it for another purpose and i edited all the stuff that need change but now I suddenly run into an error on a line which makes no sense.. Can someone take a look what is wrong here?

 

Notice: Undefined variable: mysqli in /home/schoolme/public_html/view.php on line 23

Fatal error: Call to a member function query() on a non-object in /home/schoolme/public_html/view.php on line 23

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
        <head>  
                <title>View Records</title>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        </head>
        <body>
                
                <h1>View Records</h1>
                
                <p><b>View All</b> | <a href="view-paginated.php">View Paginated</a></p>
                
                <?php
                
                    # errors weergeven
                    ini_set('display_errors',1); // 1 == aan , 0 == uit
                    error_reporting(E_ALL | E_STRICT);
                
                        // connect to the database
                        include('db_config.php');
                        
                        // get the records from the database
                        if ($result = $mysqli->query("SELECT * FROM scholen ORDER BY naam"))
                        {
                                // display records if there are records to display
                                if ($result->num_rows > 0)
                                {
                                        // display records in a table
                                        echo "<table border='1' cellpadding='10'>";
                                        
                                        // set table headers
                                        echo "<tr><th>id</th><th>Naam</th><th>Type</th><th>Geloof</th><th>Adres</th><th>Postcode</th><th>Plaats</th><th>Provincie</th><th>Telefoon</th><th>Fax</th><th>E-mail</th><th>Website</th><th></th><th></th></tr>";
                                        
                                        while ($row = $result->fetch_object())
                                        {
                                                // set up a row for each record
                                                echo "<tr>";
                                                echo "<td>" . $row->id . "</td>";
                                                echo "<td>" . $row->naam . "</td>";
                                                echo "<td>" . $row->type . "</td>";
                                                echo "<td>" . $row->geloof . "</td>";
                                                echo "<td>" . $row->adres . "</td>";
                                                echo "<td>" . $row->postcode . "</td>";
                                                echo "<td>" . $row->plaats . "</td>";
                                                echo "<td>" . $row->provincie . "</td>";
                                                echo "<td>" . $row->telfoon . "</td>";
                                                echo "<td>" . $row->fax . "</td>";
                                                echo "<td>" . $row->email . "</td>";
                                                echo "<td>" . $row->website . "</td>";
                                                echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>";
                                                echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>";
                                                echo "</tr>";
                                        }
                                        
                                        echo "</table>";
                                }
                                // if there are no records in the database, display an alert message
                                else
                                {
                                        echo "No results to display!";
                                }
                        }
                        // show an error if there is an issue with the database query
                        else
                        {
                                echo "Error: " . $mysqli->error;
                        }
                        
                        // close database connection
                        $mysqli->close();
                
                ?>
                
                <a href="records.php">Add New Record</a>
        </body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/282379-mysqli-view-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.