Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Custom error message

$
0
0

Hey there, 

I have recently been drafted in by a friend to help create a web page that can be used externally alongside his website that he has recently created on bigcartel.com. The purpose of the page is to allow his shoppers to enter into a competition and have there details stored in a database so its easy enough for him to pick a winner. To ensure that each shopper could only enter once I made sure that the email input in the database field would be unique and hence forth return an error message which it does however I would like to use a custom error message. This is something that I have been unable to achieve though. 

The code that I have been trying to adapt and change is a piece of code that I got when I was at college so its been written for the purpose of getting a message to appear when an entry has been added successfully which works well but alongside that I want the error message to work too.

 

heres my code:

 

<?php 
$connection = mysql_connect("localhost","root",""); 
if (!$connection) {
die("Database connection failed: " . mysql_error());
}
 
 
please help!! any help would be greatly appreciated 
 
$db_select = mysql_select_db("sourcedclothes",$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
 
//The PHP isset function is used to check that the submit button //on the form has been
// clicked before any processing takes place. The return value //will be either true or false
 
if (isset($_POST['add_friend'])) { 
 
$sql="INSERT INTO competition (title, name, surname, phone, email) VALUES('$_POST[title]','$_POST[name]','$_POST[surname]','$_POST[phone]','$_POST[email]')";
}
 
if (!mysql_query($sql,$connection));
  {
  die('Your details have been added to the system' . mysql_error());
  }
 
mysql_close($connection);
?>

Viewing all articles
Browse latest Browse all 13200

Trending Articles