Jump to content

die function to allow html codes not stop every code when initiated.


Minimeallolla

Recommended Posts

how can i use die but still continue with the html in the rest of code instead of stopping all codes from where die is initiated.

i want to die (insert into database) but then still allow the html codes below the die function to work still. \=

I think you have no alternative there except to modify your code so it will skip the remainder if there's an error.  Eg you can create a variable $error, set it to true when you encounter an error, and have subsequent code only execute if $error is still false.

 

Or you can use exceptions and a try/catch block to break out of the code.

 

 

<div id="mydiv">

	  <a href="javascript:;" onmousedown="if(document.getElementById('mydiv').style.display == 'block')
	{ document.getElementById('mydiv').style.display = 'block'; }
	else{ document.getElementById('mydiv').style.display = 'none'; }">Hide/Show comments</a>

<div class='navbar'><br>

<?php
include ("database.php");
$query = ("SELECT * FROM homecomments");
$result = mysql_query("SELECT * FROM homecomments");
while($row = mysql_fetch_array($result))
{
include ("echocomments.php");
}

	ini_set ("display_errors", "1");
	error_reporting(E_ALL);

		if (isset($_POST['submit'])) {

$check = mysql_query("SELECT active FROM users WHERE active ='1' AND username='$username'") or die(mysql_error());

$check2 = mysql_num_rows($check);
if ($check2 != 1) {
       die('You are not allowed to comment untill your account is activated.');
   }else{

$comment = mysql_real_escape_string(stripslashes(trim($_POST['comment'])));
$username = mysql_real_escape_string(stripslashes(trim($_COOKIE['ID_my_site'])));

$usercheck = ( $_COOKIE['ID_my_site'] ); 
$commentcheck = $_POST['comment'];
$check = mysql_query("SELECT * FROM homecomments WHERE comment = '$commentcheck' AND username = '$usercheck'") or die(mysql_error());
$check2 = mysql_num_rows($check);

	//my so called anti spam 

if ($check2 != 0) {
die('Anti Spam has detected multiple comments posted.');
				}


        	// now we insert it into the database
$insert = "INSERT INTO homecomments (username, comment)
VALUES ('$username', '$comment')";

$add_member = mysql_query($insert);
{
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php\">";
  }
}
} 
?>

<br>
<p>
<center>

<form name="commentbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0">
<textarea name="comment" cols="20" rows="2" onclick="document.commentbox.comment.value='';">Comment...</textarea>
</td></tr>
<tr><th colspan=2><input type="submit" name="submit" value="Submit">
<colspan=2><input type="submit" name="refresh" value="Refresh"></th></tr> </table>
</form><br />
</div></div>
<a href="javascript:;" onmousedown="if(document.getElementById('mydiv').style.display == 'none')
{ document.getElementById('mydiv').style.display = 'block'; }
else{ document.getElementById('mydiv').style.display = 'none'; }">Hide/Show comments</a>


<br>

as you can see this code " if ($check2 != 0) {

die('Anti Spam has detected multiple comments posted.');

} "

ends everything else if double posted. i want to like display a message but still show the comment section etc. not display a message and cut everything else out.

 

it is also the same problem with "        die('You are not allowed to comment untill your account is activated.');

  }else{ "

 

do you get what im trying to do?

How about this:

 

 if ($check2 != 0) {
echo('Anti Spam has detected multiple comments posted.');
}
else
{


        	// now we insert it into the database
$insert = "INSERT INTO homecomments (username, comment)
VALUES ('$username', '$comment')";

$add_member = mysql_query($insert);
}

 

I'm not sure if that's the exact code you want to skip, but the general idea should work.

that really does not make a difference because im only echoing a message not calling a function or file? \= well i have a line on the website saying hide/show comments and onclick it hides/shows the comments, obviously, but if you post the same comment twice it will end the comment section and only show the comments and echo at the very bottom the message and you can "glitch" the site by click hide/show comments because there should be 2, it hides all the comments and i made it abit complex so since there is only one hide/show comments theres no way of redisplaying the comments \= .  its not something that is going to effect the site greatly or even something that few will notice but its just a little "bug" that i would like to fix

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.