Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Super Basic Newbie Question

Featured Replies

Hey guys, so I've started learning some PHP at last and I can't seem to connect to the database, getting really odd error, code seems fine to me?

 

(Only following a simple tutorial, error I'm getting is as follows:)

 

Parse error: syntax error, unexpected T_STRING in /home/palmer/public_html/demo.php on line 4

 

PHP:

<?php
 
define('DB_NAME', 'forms1');
define('DB_USER', 'palmer_adventure');
define('DB_PASSWORD', 'test');
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());
}
 
echo 'Connected Sucesfully';
 
 
mysql_close();
?>

Edited by Crispy

  • Author

I just tried this code also lol (also tried moving all code off line 4 and still said it doesn't like line 4!!)

 

 

 
<?php
 
$db_hostname = 'localhost';
$db_database = 'forms1';
$db_username = 'root';
$db_password = '';
 
$link = mysql_connect($db_hostname, $db_username, $db_password);
 
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
 
$db_selected = mysql_select_db($db_database, $link);
 
if (!$db_selected) {
    die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
 
echo 'Connected Sucesfully';
 
 
mysql_close();
?>
 

I'd guess at the first code you posted this line

 

define('DB_HOST', localhost');

 

is missing an apostrophe before localhost

 

define('DB_HOST',' localhost');

  • Author

Thanks for the help guys, I've signed up for Treehouse so I'm going to learn a load more before diving in I think!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.