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 Quote 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"; Quote 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. Quote 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... Quote 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...
Solution KickStarter Posted March 20, 2013 Author Solution 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.