-1

MyPHP code that I wrote keeps printing everything that I wrote onto the web page. Here is a picture:

enter image description here

And here is the source code:

<?php
   define('DB_NAME', 'reg_form');
   define('DB_USER', 'root');
   define('DB_PASSWORD', '');
   define('DB_HOST', 'localhost');

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

    if (!$link) {
    die('Could not connect: ' . mysql_error());
}

    $db_selected = mysql_select_db(DB_NAME, $link);

    if (!db_selected) {
    die('Can\'t use ' . DB_NAME ': ' . mysql_error());
}
?>

Thanks. - Hayes Derbyshire

3 Answers3

4

It looks like your opening your code directly in your browser instead of running it through a web server. You can either upload your code to a web server that supports PHP or install one on your computer. I would recommend looking at XAMPP from http://www.apachefriends.org I've used this project for development many times and it is quick and easy to setup.

lede
  • 182
  • 2
1

You're are opening file - so it's shows it content. You need move this document to localhost root folder.

1

Looks like you're opening a local .php file into your web browser? That's why it's displaying the text within the file.

If you're wanting this to run, it'll need to be hosted server-side and called, probably through html, for it to be ran and displayed.

Consider downloading MAMP. It's a server program you can use to work on these kinds of projects while staying local.

Hope this helps!

Spookytheboy
  • 228
  • 1
  • 6
  • 19