0

my I am trying to make login registration page in php. apache and mysql is up and running.

I am executing the following code

<?php 
$db_host = "localhost:777";
$db_username = "root";
$db_pass = "";
$db_name = "login";

mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysql_select_db("$db_name") or die ("no database");             
?>

I am using localhost:777 because port 80 is being used by skype.

phpMyAdmin is up and running.

The output i am getting is nothing but the above code only.

can anyone help me on this issue?

Mohammed
  • 637
  • 13
  • 26
  • Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). If you're getting code output you're not running your server or it is not configured correctly. – Jay Blanchard Nov 24 '14 at 20:38
  • look at this [post](http://stackoverflow.com/questions/14073985/xampp-apache-server-is-not-starting-after-skype-installation) hope it will help you fix the port problem – alda1234 Nov 24 '14 at 20:44
  • what server are you using?, Wamp or xammp. secondly where do you configure the port no 777 – Sectona Nov 24 '14 at 21:43
  • hey @JayBlanchard server is up and running because iam able to display login page – Mohammed Nov 24 '14 at 21:55
  • @sheikhsabeer? how are accessing the page? – Jay Blanchard Nov 24 '14 at 21:55
  • hi @JayBlanchard Iam trying to make login registration .... server is running i can see "it works" when i click on admin button of apache in xampp – Mohammed Nov 24 '14 at 22:02
  • I know @sheikhsabeer, but how are you accessing the page? Are you going to http://localhost/login.php? – Jay Blanchard Nov 24 '14 at 22:03
  • @JayBlanchard i made a login page from login page i am tried to call mysqlconnect.php but i didin'twork so i wrote standalone php code to test the connection but it is showing me the code itself – Mohammed Nov 24 '14 at 22:06
  • @sheikhsabeer we do not have enough information to help you solve the issue. If you're seeing code when you're running the page a.) the page is not in the htdocs folder of XAMPP or, 2.) the server is not configured correctly or, 3) the server is not running. – Jay Blanchard Nov 24 '14 at 22:08
  • my code in "C:\xampp\htdocs" and server is running ... i think i changed the default port in "httpf.conf" from 80 to "777"...so do i need to make changes in any other place too? – Mohammed Nov 24 '14 at 22:18

1 Answers1

0
  1. Use MySQLi or PDO not MySQL.
  2. You're passing the variables as a string using " " in the mysql_connect function

The syntax is as follows: mysqli_connect(host,username,password,dbname,port,socket);

<?php
$db_host = "localhost";
$db_port = "777";
$db_username = "root";
$db_pass = "";
$db_name = "login";

$conn = mysqli_connect($db_host,$db_username,$db_pass,$db_name,$db_port);

if (mysqli_connect_errno())
     {
         echo "Failed to connect to MySQL: " . mysqli_connect_error();
     }
?>

Try that and it should work. Please make sure you understand the code above and the error you made. Do not simply copy and paste please you will not learn from it.

Enayet Hussain
  • 908
  • 4
  • 17
  • 33