Jump to content

[SOLVED] connection to database or die message


gfmitchell

Recommended Posts

Hi can anyone help me as I'm new to php.

When connection to the database fails I would like to include an email link in the response message, but I need help with how it can be done.  Below is my code and I want the error message text to include a Report This email html link. 

<?php

//connect to MySQL

$host = "localhost";

$user = "username";

$pass = "password";

$error = "There is a problem with connection to the server please Report This (email link here)";

$connect = mysql_connect($host,$user,$pass) or die ($error);

?>

Thanks for the help

You can try like this, $email variable holds your email id

<?php 
//connect to MySQL
$email = "[email protected]"; // change your email here 
$host = "localhost";
$user = "username";
$pass = "password";
$error = "There is a problem with connection to the server please Report This (<a href=\"mailto:$email\"'>Click here to mail<a>)";
$connect = mysql_connect($host,$user,$pass) or die ($error);
?>

just to add a bit more here is the full code to add a subject and body to the email.

<?php

//connect to MySQL

$host = "localhost";

$user = "username";

$pass = "password";

$email = "[email protected]";

$subject = "connection.php";

$body = "There is a problem with the connection to the database, please investigate";

$error = "There is a problem with connection to the server please

(<a href=\"mailto:$email?subject=$subject&body=$body\"'>Report This<a>)";

$connect = mysql_connect($host,$user,$pass) or die ($error);

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.