Yuki Posted March 24, 2008 Share Posted March 24, 2008 if the sql fails and it prints out what's int die('') it doesn't proceed through the rest of the script, if it fails I want it to just show a notification saying "failed" but also finish the script (pulls out data from db and shows it) Any way? Quote Link to comment https://forums.phpfreaks.com/topic/97544-mysql-or-die/ Share on other sites More sharing options...
MadTechie Posted March 24, 2008 Share Posted March 24, 2008 was their a question in that ? ??? see manual die AKA exit do you have some sample code ? Quote Link to comment https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499105 Share on other sites More sharing options...
marklarah Posted March 24, 2008 Share Posted March 24, 2008 Post your code Quote Link to comment https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499106 Share on other sites More sharing options...
Yuki Posted March 24, 2008 Author Share Posted March 24, 2008 if(isset($_POST['submit'])) { $question_Desc = $_POST['question_Desc']; $question_EndDate = $_POST['question_EndDate']; $question_Week = $_POST['question_Week']; $query = "INSERT INTO question (question_Desc, question_Week, question_Correct_Answer, question_EndDate, module_Code) VALUES ('$question_Desc', $question_Week, 0, '$question_EndDate', '$module')"; $echo = "Failed adding the question to the database"; mysql_query($query)or die("<script type='text/javascript'> var divid = document.getElementById('notify'); divid.style.display = 'block'; divid.innerHTML = '".$echo."'; </script>"); // the code you want to echo // script to display it $echo = "Succeeded adding the question to the database"; // script to display it echo "<script type='text/javascript'> var divid = document.getElementById('notify'); divid.style.display = 'block'; divid.innerHTML = '".$echo."'; </script>"; } The question is, when the mysql fails, it goes on to die(), and then doesn't continue print below (which is html) I need an alternative to die for catching mysql errors Quote Link to comment https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499109 Share on other sites More sharing options...
marklarah Posted March 24, 2008 Share Posted March 24, 2008 a lazy way round, but just try @mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499110 Share on other sites More sharing options...
Barand Posted March 24, 2008 Share Posted March 24, 2008 <?php $result = mysql_query ("SELECT foo FROM bar"); if (!$result) echo "Query failed"; // rest of script follows ... ?> But if the query fails, how can you pull and show the data? Quote Link to comment https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499112 Share on other sites More sharing options...
MadTechie Posted March 24, 2008 Share Posted March 24, 2008 maybe this if(isset($_POST['submit'])) { $question_Desc = $_POST['question_Desc']; $question_EndDate = $_POST['question_EndDate']; $question_Week = $_POST['question_Week']; $query = "INSERT INTO question (question_Desc, question_Week, question_Correct_Answer, question_EndDate, module_Code) VALUES ('$question_Desc', $question_Week, 0, '$question_EndDate', '$module')"; $check = mysql_query($query) if($check) { $msg = "Succeeded adding the question to the database"; }else{ $msg = "Failed adding the question to the database"; } echo "<script type='text/javascript'>\n var divid = document.getElementById('notify');\n divid.style.display = 'block';\n divid.innerHTML = '$msg';\n </script>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499113 Share on other sites More sharing options...
Yuki Posted March 24, 2008 Author Share Posted March 24, 2008 http://shahinrostami.com/webdevass2/question.phps is where the full code for this page is if you need to see Quote Link to comment https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499116 Share on other sites More sharing options...
Yuki Posted March 24, 2008 Author Share Posted March 24, 2008 maybe this if(isset($_POST['submit'])) { $question_Desc = $_POST['question_Desc']; $question_EndDate = $_POST['question_EndDate']; $question_Week = $_POST['question_Week']; $query = "INSERT INTO question (question_Desc, question_Week, question_Correct_Answer, question_EndDate, module_Code) VALUES ('$question_Desc', $question_Week, 0, '$question_EndDate', '$module')"; $check = mysql_query($query) if($check) { $msg = "Succeeded adding the question to the database"; }else{ $msg = "Failed adding the question to the database"; } echo "<script type='text/javascript'>\n var divid = document.getElementById('notify');\n divid.style.display = 'block';\n divid.innerHTML = '$msg';\n </script>\n"; } Hi thanks but that tells me it's succeeded even if it hasn't! Quote Link to comment https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499118 Share on other sites More sharing options...
Yuki Posted March 24, 2008 Author Share Posted March 24, 2008 <?php $result = mysql_query ("SELECT foo FROM bar"); if (!$result) echo "Query failed"; // rest of script follows ... ?> But if the query fails, how can you pull and show the data? previous data that has been entered, it's a list of questions with a form on the page to add more EDIT: Solved, thanks a lot everyone. There was some code after that was interfering that I removed. Quote Link to comment https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499121 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.