Jump to content

need help to replace die with $error funcation ....


Simon180

Recommended Posts

I been trying to replace all my die messages with $error so i can handly my error messages better in a echo format below are codes i been trying to convert first one is the old die command version and other one is my $error version I dont no how to set my error funcations up :(

 

Old Version (Working with Die )

// Email Account Check
$msgcheck = $_POST['message'];
$check = mysql_query("SELECT username FROM support WHERE message = '$msgcheck'")
or die(mysql_error());
$checkmsg = mysql_num_rows($check);

if ($checkip != 0)
    die('<p>Sorry, the following message [ <b>'.$_POST["message"].'</b> ] is already in our support database.</p>');

 

Below is my version with $error funcation

 

// Email Account Check
$msgcheck = $_POST['message'];
$check = mysql_query("SELECT username FROM support WHERE message = '$msgcheck'")
or die(mysql_error());
$checkmsg = mysql_num_rows($check);

if ($checkmsg != 0)
{
if ($error == "") 
{
    $error = "<p>Sorry, the following message [ <b>'.$_POST["message"].'</b> ] is already in our support database.</p>";
}

 

I want to make it so I can all all error messages in $error so when i use <?php echo($error) ?> in a page it will list the current errror can anyone help plz? thanks

Link to comment
Share on other sites

ok i got it to work with my code but the new problem is even no it find there allready a message in the database it still submits it I need to stop the process sum how anyidears????

 

// Message Check
$msgcheck = $_POST['message'];
$check = mysql_query("SELECT username FROM support WHERE message = '$msgcheck'")
or die(mysql_error());
$checkmsg = mysql_num_rows($check);

if ($checkmsg != 0)
    $error = ('<p>Sorry, the following message [ <b>'.$_POST["message"].'</b> ] is already in our support database.</p>');

 

thanks alot

Link to comment
Share on other sites

no all am doing it checking the messagefield and if there try to add the same msg thats in the field it will now allow them it works but it still adds the message to database even no it picks it up as being in there i need it so when it find the database entry it will stop the add funcation (kill it self) like the die() but with out using die as i can not use that on my website as it makes it look messy for sum reason!

Link to comment
Share on other sites

// Email Account Check
$msgcheck = $_POST['message'];
$check = mysql_query("SELECT username FROM support WHERE message = '$msgcheck'")
or die(mysql_error());
$checknum = mysql_num_rows($check);

if (!$checknum){
    echo('<p>Sorry, the following message [ <b>'.$_POST["message"].'</b> ] is already in our support database.</p>');
}
else{
   # do query 
}

Link to comment
Share on other sites

// Message Check
$msgcheck = $_POST['message'];
$check = mysql_query("SELECT username FROM support WHERE message = '$msgcheck'")
or die(mysql_error());
$checkmsg = mysql_num_rows($check);

if (!$checknum != 0) {
$error = ('<p>Sorry, the following message [ <b>'.$_POST["message"].'</b> ] is already in our support database.</p>');
} else {
die():
}

 

MySQL

 

CREATE TABLE `support` (                                   
           `id` mediumint(11) NOT NULL auto_increment,              
           `username` varchar(100) default NULL,                    
           `email` varchar(100) default NULL,                       
           `title` varchar(1000) default NULL,                      
           `message` mediumtext,                                    
           `date` varchar(100) default NULL,                                             
           PRIMARY KEY  (`id`)                                      
) ENGINE=MyISAM AUTO_INCREMENT=139 DEFAULT CHARSET=latin1;

 

and post

 

$messagefield = $_POST["message"];

 

 

hop it helps

Link to comment
Share on other sites

you mean the data in the data base or the email??? here both

 

Email:

 

Simon, has sent the following data :

==================================
Username: Simon
Email: simon@msn.com

Message:
test my message
==================================

 

SQL Data

 

insert  into `support`(`id`,`username`,`email`,`title`,`message`,`date`,`ip`) values 
(139,'Simon','simon@msn.com','info@yoursite.com','testing ....','09-12-2007','Hidden');

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.