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

Link to comment
Share on other sites

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

<?php 
//connect to MySQL
$email = "you@domain.com"; // 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);
?>

Link to comment
Share on other sites

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 = "you@you.com";

$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);

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.