Jump to content

mysql or die


Yuki

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499109
Share on other sites

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";
}

Link to comment
https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499113
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499118
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/97544-mysql-or-die/#findComment-499121
Share on other sites

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.