newsha99 Posted April 20, 2017 Share Posted April 20, 2017 I wrote a connect.php to connect my databases with the registration and login forms It's saying it is finding an error in line 2 of my code which has the $host_name variable. here's my code. I dont know what im doing wrong <? php $host_name="db678077635.db.1and1.com"; $database="db678077635"; $username="dbo678077635" I wrote a connect.php to connect my databases with the registration and login forms It's saying it is finding an error in line 2 of my code which has the $host_name variable. here's my code. I dont know what im doing wrong <? php $host_name="db678077635.db.1and1.com"; $database="db678077635"; $username="dbo678077635"; $password="[mypassword]"; $connect= mysqli_connect($host_name, $username, $password, $database); if (mysqli_connect_errno()){ echo "<p> Failed to connect to MySQL:'.mysqli_connect_error()'.</p>"; } else{ echo "<p> Connection to MySQL server successfully established.</p>"; } ?> $connect= mysqli_connect($host_name, $username, $password, $database); if (mysqli_connect_errno()){ echo "<p> Failed to connect to MySQL:'.mysqli_connect_error()'.</p>"; } else{ echo "<p> Connection to MySQL server successfully established.</p>"; } ?> Link to comment Share on other sites More sharing options...
benanamen Posted April 20, 2017 Share Posted April 20, 2017 You have a space in line 1. Use a proper IDE and you will see these simple mistakes. <? php Should be <?php Link to comment Share on other sites More sharing options...
benanamen Posted April 20, 2017 Share Posted April 20, 2017 This line is a security risk. Do not ever put this in your code. if (mysqli_connect_errno()){ echo "<p> Failed to connect to MySQL:'.mysqli_connect_error()'.</p>"; } Link to comment Share on other sites More sharing options...
newsha99 Posted April 20, 2017 Author Share Posted April 20, 2017 This line is a security risk. Do not ever put this in your code. if (mysqli_connect_errno()){ echo "<p> Failed to connect to MySQL:'.mysqli_connect_error()'.</p>"; } why is that? Link to comment Share on other sites More sharing options...
benanamen Posted April 20, 2017 Share Posted April 20, 2017 By doing that you are outputting internal errors to the user who has absolutely no use for that information. The one it is useful to is a hacker. You will need to learn proper error handling. Since you are just starting out, now would be the time to start using PDO. You will find it easier to work with as well. Start with this tutorial https://phpdelusions.net/pdo Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.