0

Supposedly the PHP file should connect to the database. But whenever I click the submit button, it print out the code itself :c

PHP CODE:

<?php
    $host = "localhost";
    $sname = "root";
    $database = "products";
    mysql_connect("$host","$sname") or die(mysql_error());
    echo "connected successfully!";

    mysql_select_db("$database") or die(mysql_error());
    echo "Database selected successfully!";
?>

This is how my html code looks like: Deleted the code inside it because its too long

<form action="registration.php">
    .....
    .....
</form>
LuckyStarr
  • 1,468
  • 2
  • 26
  • 39
juju17
  • 271
  • 4
  • 15
  • 2
    Did you saved the file with `.php` extension – Narendrasingh Sisodia Dec 14 '15 at 08:55
  • 2
    Because you are not running the code in server! Use hosting or localhost – Thamilhan Dec 14 '15 at 08:55
  • More explanation, the php code isn't running at all OR it isn't acting as a code itself. It is only treated as a "text". The output is the code itself. – juju17 Dec 14 '15 at 08:56
  • 1
    how you are accessing your script on browser? via file path or via some web server? – Chetan Ameta Dec 14 '15 at 08:57
  • extension of your page ?? .html or .php ? – Nana Partykar Dec 14 '15 at 08:58
  • If your just seeing PHP code in the browser it's because you don't have PHP enabled on your web server, therefore the server doesn't know what do with it and outputs the page as text rather than executing it. – Horaland Dec 14 '15 at 09:12
  • This can only happen in two cases. 1. You php file's extension is not .php – Amit Sarwara Dec 14 '15 at 09:15
  • My PHP file extension is ".php And PROBLEM SOLVED! I wasn't running my code in the server that's why :) Thanks – juju17 Dec 14 '15 at 09:18
  • Possible duplicate of [PHP code is not being executed (I can see it on source code of page)](http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-i-can-see-it-on-source-code-of-page) – Anders Dec 14 '15 at 10:50

1 Answers1

2

PROBLEM SOLVED! I wasn't running my code in the server that's why :) Thanks The path on the address bar should somehow look like this: 127.0.0.1/...path or localhost/...path. Somehow like that :) Thanks for the help :)

juju17
  • 271
  • 4
  • 15