Simon180 Posted September 12, 2007 Share Posted September 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/ Share on other sites More sharing options...
phat_hip_prog Posted September 12, 2007 Share Posted September 12, 2007 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); } Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346859 Share on other sites More sharing options...
Simon180 Posted September 12, 2007 Author Share Posted September 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346863 Share on other sites More sharing options...
phat_hip_prog Posted September 12, 2007 Share Posted September 12, 2007 Is the field in the db set to being UNIQUE? Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346866 Share on other sites More sharing options...
Simon180 Posted September 12, 2007 Author Share Posted September 12, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346870 Share on other sites More sharing options...
xyn Posted September 12, 2007 Share Posted September 12, 2007 do an if. if there is an error. dont run the query. and display a message. Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346872 Share on other sites More sharing options...
Simon180 Posted September 12, 2007 Author Share Posted September 12, 2007 am new can you do that if then statment please?? Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346874 Share on other sites More sharing options...
xyn Posted September 12, 2007 Share Posted September 12, 2007 // 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 } Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346880 Share on other sites More sharing options...
Simon180 Posted September 12, 2007 Author Share Posted September 12, 2007 ok I tryed that still submited it shows the error message but still submits Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346890 Share on other sites More sharing options...
phat_hip_prog Posted September 12, 2007 Share Posted September 12, 2007 can you show the table data and show your $_POST['message'] Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346891 Share on other sites More sharing options...
Simon180 Posted September 12, 2007 Author Share Posted September 12, 2007 // 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 Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346895 Share on other sites More sharing options...
phat_hip_prog Posted September 12, 2007 Share Posted September 12, 2007 No, the actual data! Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346900 Share on other sites More sharing options...
Simon180 Posted September 12, 2007 Author Share Posted September 12, 2007 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'); Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346910 Share on other sites More sharing options...
phat_hip_prog Posted September 12, 2007 Share Posted September 12, 2007 Try printing out all the variables on the page with echo to debug... I just can't see what's wrong! p.s. I believe varchar has a max size of 256! Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346924 Share on other sites More sharing options...
Simon180 Posted September 12, 2007 Author Share Posted September 12, 2007 it all works it just it dont DIE if it find the message allready in the database it still posts it! Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346927 Share on other sites More sharing options...
phat_hip_prog Posted September 12, 2007 Share Posted September 12, 2007 Try exit() or wrap all rest in logic brackets? Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346932 Share on other sites More sharing options...
Simon180 Posted September 12, 2007 Author Share Posted September 12, 2007 try Exit(); and Die(); but when i use them it mess's my website up really badly thats why I want to use $error so i can remove the Die command as showing error messages Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346938 Share on other sites More sharing options...
phat_hip_prog Posted September 12, 2007 Share Posted September 12, 2007 Use logic Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346941 Share on other sites More sharing options...
Simon180 Posted September 12, 2007 Author Share Posted September 12, 2007 ???? Quote Link to comment https://forums.phpfreaks.com/topic/69007-need-help-to-replace-die-with-error-funcation/#findComment-346958 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.