KickStarter Posted March 20, 2013 Share Posted March 20, 2013 Hello everybody. I am trying to connect my website to the database. However, I keep getting an error in my php code to connect to the database. Heres the code: <?php $sqlhostname = "localhost"; $sqlusername = "root"; $sqlpassword = ""; $sqldatabase = "login" $conn = mysql_connect($sqlhostname, $sqlusername, $sqlpassword) or die(mysql_error()); if($conn){ mysql_select_db($sqldatabase); }else{ print("can't connect to database"); } ?> When I test my php file using wampserver, I get the following error: " Parse error: syntax error, unexpected '$conn' (T_VARIABLE) in C:\wamp\www\web\mysql.php on line 7" What am I missing? It looks right from my perspective. Also, I am quite new to PHP. Thanks Link to comment https://forums.phpfreaks.com/topic/275935-help-cant-get-database-connection-to-work/ Share on other sites More sharing options...
PaulRyan Posted March 20, 2013 Share Posted March 20, 2013 $sqldatabase = "login"; Link to comment https://forums.phpfreaks.com/topic/275935-help-cant-get-database-connection-to-work/#findComment-1419916 Share on other sites More sharing options...
KickStarter Posted March 20, 2013 Author Share Posted March 20, 2013 $sqldatabase = "login"; Yeah, thats the name of my database in phpMyAdmin. I tried changing it to a tablename, but that doesnt work either. Link to comment https://forums.phpfreaks.com/topic/275935-help-cant-get-database-connection-to-work/#findComment-1419917 Share on other sites More sharing options...
PaulRyan Posted March 20, 2013 Share Posted March 20, 2013 You missed the semi-colon... Link to comment https://forums.phpfreaks.com/topic/275935-help-cant-get-database-connection-to-work/#findComment-1419920 Share on other sites More sharing options...
KickStarter Posted March 20, 2013 Author Share Posted March 20, 2013 You missed the semi-colon... Ohh how did i not see that. Just had a long day today. Nevertheless, thanks a lot Link to comment https://forums.phpfreaks.com/topic/275935-help-cant-get-database-connection-to-work/#findComment-1419924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.