-1
<!Doctype html>
<html>
<head>
<title>Orders Database</title>
</head>
<body>
<?php
$con = mysql_connect('localhost','wrobell1_1','123');
$db = mysql_select_db('wrobell1_orders',$con);

if($con){ 
echo 'succefully connected'} 
?>
</body>
</html>

What can be wrong? I put it on the server in public html folder and nothing displays

5 Answers5

1

You have syntax error in code.

<!Doctype html>
<html>
<head>
<title>Orders Database</title>
</head>
<body>
<?php
$con = mysql_connect('localhost','wrobell1_1','123');
$db = mysql_select_db('wrobell1_orders',$con);

if($con){ 
  echo 'succefully connected';
} 
?>
</body>
</html>
Prashant G Patil
  • 927
  • 1
  • 8
  • 22
0

Can it be because of the hosting server?
If anyone could paste the proper code I would be very grateful I have one hour to complete it ;(

0

You need to test whether there's a syntax error on your page first. I usually do this with a simple echo. if the code below does not shows the message There is NO syntax error. then there is an syntax error.

I also test the connection directly after making it.

<!Doctype html>
<html>
<head>
<title>Orders Database</title>
</head>
<body>
<?php
// is there a syntax error?
echo 'There is NO syntax error.<br>';
// connect 
$con = mysql_connect('localhost','wrobell1_1','123');
if ($con) echo 'We successfully connected.<br>';
          echo 'The connection failed.<br>';
// select database 
$db = mysql_select_db('wrobell1_orders',$con);
if ($db) echo 'We successfully selected.<br>';
          echo 'The selection failed.<br>';
?>
</body>
</html>

And you already know the mysql extension should not be used. Use mysqli or PDO.

KIKO Software
  • 15,283
  • 3
  • 18
  • 33
  • Which version of php is it? – Przemek Wróbel Mar 31 '17 at 08:20
  • @Przemek: What does your 'it' refer to? If it is the code I wrote then clearly there is no specific version. If it is about the mysql extension then this is deprecated as of PHP 5.5.0 (20 Jun 2013). – KIKO Software Mar 31 '17 at 08:45
  • What I mean is from what I`ve read from 5.5 mysql_connect doesn`t work, and i just wanted to know if it is for previous version. Now I ve read the caption:" And you already know the mysql extension should not be used. Use mysqli or PDO." Thanks! :d – Przemek Wróbel Mar 31 '17 at 12:56
0

you miss ;

it should be

echo 'succefully connected';
Cakka
  • 322
  • 2
  • 7
0

The might be two problems with your connection code. 1. The live server on might be using a php version that does not support the mysql_* functions that you are using, they are depreciated and no longer used, in the newer php version, better use mysqli or pdo.

The host might be incorrect? check the host,username and password are correct. When you are on cpanel you can login to phpmyadmin from there once login you may see, the host/server name : its wtitten server:whatever make sure on your communication you write that server name screenshot shows how to see the server name from phpmyadmin of a live server, from your cpanel.

The third and obvious one is the syntax error here : echo 'succefully connected'} there's a semicolon missing which then should generate an error, thus makking your question a possible duplicate of : PHP Parse/Syntax Errors; and How to solve them?

Better start using mysqli or pdo rather than mysql_* functions

Check if your host is indeed correct is localhost, you can check that on php myadmin

enter image description here

Proper connection

<?php
$servername = "localhost";
$username = "wrobell1_1";
$password = "123";
$dbname = "wrobell1_orders";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
?>
Community
  • 1
  • 1
Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34