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

Could try modyfing this to your needs:

function do_mysql_query($s, $conn)
{
try
{
	if ( !@ ($res = mysql_query($s, $conn)) )
		throw new Exception (mysql_error());
}
catch (Exception $e)
{
	//echo 'ERROR: ' . $e->getMessage();
	return array(-1, $res);
}
return array(0, $res);
}

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

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!

// 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 
}

// 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

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

 

Email:

 

Simon, has sent the following data :

==================================
Username: Simon
Email: [email protected]

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

 

SQL Data

 

insert  into `support`(`id`,`username`,`email`,`title`,`message`,`date`,`ip`) values 
(139,'Simon','[email protected]','[email protected]','testing ....','09-12-2007','Hidden');

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.