soma56 Posted June 12, 2010 Share Posted June 12, 2010 I'm attempting to learn how to connect PHP with MySQL. The sample materials I'm learning from don't have any display issues, however, when I run the code I receive the following error: Notice: Use of undefined constant db - assumed 'db' in C:\mypath\databases.php on line 4 My code is relatively simple and I should note that I'm completely new to learning this stuff. <?PHP //1. Create a database connection $db = mysql_connect("localhost", "root", "mypassword"); if (!db) { die("Database connection failed: " . mysql_error()); } ?> Suggestions? Link to comment https://forums.phpfreaks.com/topic/204580-notice-use-of-undefined-constant/ Share on other sites More sharing options...
kenrbnsn Posted June 12, 2010 Share Posted June 12, 2010 You forgot the '$' infront of your variable <?php if (!$db) { ?> Ken Link to comment https://forums.phpfreaks.com/topic/204580-notice-use-of-undefined-constant/#findComment-1071165 Share on other sites More sharing options...
soma56 Posted June 12, 2010 Author Share Posted June 12, 2010 @kenrbnsn Thankyou. Link to comment https://forums.phpfreaks.com/topic/204580-notice-use-of-undefined-constant/#findComment-1071167 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.