0

I need help with an error on my page using MySQL.

When I try to go to the website, this text pop up:
Parse error: syntax error, unexpected 'mysql_connect' (T_STRING) in C:\xampp\htdocs\mywebsite\inc\scripts\mysql_connect.inc.php on line 11

<?php
$conn_error = 'Colud not connect.';

$mysql_host = "localhost:8080";
$mysql_user = "liam";
$mysql_pass = "";

$mysql_db = 'socialnetwork'


mysql_connect($mysql_host, $mysql_user, $mysql_pass or die("Couldn't Connect") ;
mysql_select_db('mysql_db') or die($conn_error);

echo 'Connected!'
?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
user2227874
  • 31
  • 1
  • 1
  • 9
  • You have a missing `)` in `mysql_connect($mysql_host, $mysql_user, $mysql_pass or die("Couldn't Connect") ;` Try `mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die("Couldn't Connect");` – Funk Forty Niner Apr 12 '13 at 20:52
  • also missing `;` in `echo 'Connected!'` – Funk Forty Niner Apr 12 '13 at 20:52
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – tereško Apr 12 '13 at 21:00

3 Answers3

5
$mysql_db = 'socialnetwork'
mysql_connect($mysql_host, $mysql_user, $mysql_pass or die("Couldn't Connect") ;
echo 'Connected!'

should be

$mysql_db = 'socialnetwork';
                           ^
mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die("Couldn't Connect") ;
                                                   ^
echo 'Connected!';
                 ^

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496
1

here working code

<?php
$conn_error = 'Colud not connect.';

$mysql_host = "localhost:8080";
$mysql_user = "liam";
$mysql_pass = "";

$mysql_db = 'socialnetwork' ;
mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die("Couldn't Connect") ;
mysql_select_db('mysql_db') or die($conn_error);

echo 'Connected!' ;

?>

you had 3 errors .

1- you forget ; here $mysql_db = 'socialnetwork' .

2- you forget ) here mysql_connect($mysql_host, $mysql_user, $mysql_pass.

3- you forget ; here echo 'Connected!'

echo_Me
  • 37,078
  • 5
  • 58
  • 78
0

Your forget

;

here

$mysql_db = 'socialnetwork'
unhacked
  • 131
  • 3