0

I have my first MySQL project and am stuck at the beginning with an error on the line that tries to connect to the MySQL database.

Here is the error I am getting:

enter image description here

And here is the first bit of my code including the line that is getting the error:

if (empty($_POST['first_name']) || empty($_POST['last_name']))
echo "<p>You must enter your first and last name! Click your browser's 
Back button to return to the Guest Book form.</p>";
else {
$DBConnect = @mysql_connect("localhost", "root", "");
if ($DBConnect === FALSE)
    echo "<p>Unable to connect to the database server.</p>"
    . "<p>Error code " . mysql_errno()
    . ": " . mysql_error() . "</p>";

Can anyone see what I'm doing incorrectly? I copied this right out of the book I'm working with and still get this error instead of the errors from the code.

Tony
  • 618
  • 12
  • 27
  • 1
    Mysql connect is depreciated in PHP, use Mysqli or PDO – nacho Nov 12 '20 at 20:05
  • 2
    If you copied this from a book, it must be quite an old book already. The `mysql_*` library has been replaced by `mysqli_*`, which in turn has been replaced by [PDO](https://www.php.net/manual/en/book.pdo.php). The `mysql_*` function set has been removed since PHP 7.0 – CerebralFart Nov 12 '20 at 20:06
  • 2
    @nacho not deprecated anymore. As error states the function is non-existent. – user3783243 Nov 12 '20 at 20:06
  • Additionally you should not use `root` for an application. Create a user for the application and give it appropriate security levels. – user3783243 Nov 12 '20 at 20:08
  • Thanks for your comments everyone. This is very good information to know. – Vagabond251 Nov 12 '20 at 20:10

0 Answers0