0

Whenever I try to retrieve information from my MySQL database and show it on my web page, the page shows the source instead.

The code source start after the ->fecth(). I think that my WAMP is not setup correctly or the obvious one: "I did something wrong somewhere". I am not looking for an upgrade but just for corrections.

   <?
        $bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '');
        $rep = $bdd->query('SELECT * FROM membre');

        while($data = $rep->fetch()) 
         {
              echo $data['nom'];
         }
   ?>
10
  • What errors are you getting? What's not working properly. This is a bit unclear in your question. Commented Jul 13, 2015 at 21:11
  • Looks like you're not loading from the webserver or Apache PHP is not running. Commented Jul 13, 2015 at 21:12
  • Funny why that is the output and not more if php is not activated Commented Jul 13, 2015 at 21:13
  • no errors, just query('SELECT * FROM membre'); while($data = $rep->fetch()) { echo $data['nom']; } ?> is shown when i start the page Commented Jul 13, 2015 at 21:13
  • Because <? starts a HTML tag and the > before query() closes the tag. The rest is text output. View source and you'll see it all. Commented Jul 13, 2015 at 21:14

2 Answers 2

1

Maybe you can't configured your php for accept <? open tag, try to use <?php

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

Comments

1

You might need a complete PHP tag:

<?php

You might need to have a "LoadModule" statement in your Apache config file.

LoadModule php5_module        libexec/apache22/libphp5.so

Last, quite often this is the problem --- you need AddHandler:

AddHandler application/x-httpd-php  .php

This is often system dependent. Perhaps your hosting company can help?

3 Comments

OP is not using a hosting company, this is on WAMP.
Then he'll have to fix it himself, I guess ... ;) Which is why I gave him three places to look ... :)
thanks i wasn't sure if it was the wamp messing up or my code had a problem. i'll try to figure it out then. thanks

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.