Jump to content

mysql or die


Yuki

Recommended Posts

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?

Link to comment
Share on other sites

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