0

I have a project for school. I have to create a website, connected to a database. Now, I have a problem with displaying data from my database in/on my webpage.

My database runs/is on a server of my school and created and managed with phpPgAdmin (PostgreSQL).

Here is my code:

Does someone knows the right code to represent the data from my database on my webpage?

<html>
    <head>
        <link type="text/css" rel="stylesheet" href="index_stylesheet.css"/>
        <title>Home</title>
    </head>
    <body>

        <div class="optieBalk">
            <ul>
                <li><a href="Index.php">Home</a></li>
                <li><a href="default.asp">What's New?!</a></li>
                <li><a href="login.html">Tickets</a></li>
                <li><a href="contact.html">Contact</a></li>
            </ul>
        </div>

        <div class="searchbox">
            <form action="search.php?searching=true" method="POST">
                <input type="text" name="searchcategory" value=""/>
                <input type="submit" value="Search"/>
            </form>
        </div>

        <div id="carousel">
            <p>
                <?php
                    require 'db_connect.php';
                    $result=pg_query($conn, "SELECT titel, id FROM film              WHERE id=1;");
                    if  (!$result) {
                    echo "query did not execute";
                    }
                    if (pg_num_rows($result) == 0) {
                    echo "0 records"
                    }
                    else {
                    while ($row = pg_fetch_array($result) {
                     echo "titel: $row[1]  id: $row[0]";
                     echo "<br />\n";
                    }
                    }
                ?>
            </p>
        </div>

        <div id="footer">
            <p id="dateDiv">
            </p>
        </div>
    </body>
</html>

UPDATE* I am able to access my webpage on the server. Now I only need to find out how to show the data from my database ("Kick-ass 2") properly.

http://didactiek1.edm.uhasselt.be/~sebastiaanlagaeysse/index.html

*UPDATE2 I have found the problem, and I can see the content of my database on my webpage :) The file-extension had to be .php on the server in order to execute the php-code, and not .html.

10
  • And what is the question? Commented May 31, 2013 at 20:13
  • Your code looks fine, but you need to tell us what it is doing if it is not working like you expect. We are not psychic. Commented May 31, 2013 at 20:18
  • I have no idea anymore how to show the data. Already searched on the web and applied .htaccess file and so on and on... nothing helped. The only thing it showed was: ";}}?> Commented May 31, 2013 at 20:19
  • It has to show the title: kick-ass 2. But as i mentioned, it just shows: ";}}?> . I have absolutely no idea anymore how to let it work. Commented May 31, 2013 at 20:22
  • You have to put the page on a webserver that is running php ... you can't just view it on your local machine. Commented May 31, 2013 at 20:22

2 Answers 2

1

You mention in the comments that you're getting a 403 error when viewing the php file... Frequently, this means that you've set it up as fascgi and you've misconfigured it. More often than not, it'll be because your site folder is not under the web root.

Typically, you'd want to add something like this to your apache config file:

<IfModule mod_fastcgi.c>
    # Without the following directive, you'll get an Access Forbidden error
    # when the path aliased by /php-fpm is not under the document root:
    <Location /php-fpm>
        Order Deny,Allow
        Deny from all
        Allow from env=REDIRECT_STATUS
    </Location>
</IfModule>
Sign up to request clarification or add additional context in comments.

1 Comment

ok thank you. I can view my webpage now, now the only problem I'm left with, is the correct data from database that has to be shown. As I mentioned it shows : ":}}?> but it has to show Kick-ass 2.
0

As I said in my comment, I'm able now to view the content on my webpage. For those people who helped me or tried, thank you! :D

It was a problem related to the file-extension. It has to be .php in order to execute the php-code on the server and not .html. Pretty stupid mistake I see now :)

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.