Here is what I am trying to do.

I have a page where the user can delete there own posts they make in a message board. Basically what I am trying is when they click on the "delete message" button it prompts them with a javascript confirm box.

Depending on what the user choses it either executes a delete SQL query or not

Basically what I tried is this
<script type="text/javascript">
var areYouSure=confirm("Are you sure you want to delete?")
if (areYouSure==true)
{
document.write("<? code here?>")
}
else
{
}
</script>

It keeps giving me parse errors though. Anyway if there must be a way to do this?

Any help would be great!!
Adam

    What is the exact parse error. also is that the exact way your doing it?

      It just says this

      Parse error: parse error in
      ..etc/board.php on line 189

      here is exactly what I have
      <script type="text/javascript">
      var areYouSure=confirm("Are you sure you want to delete this?")
      if (areYouSure==true)
      {
      document.write("<?")
      document.write("$query = \"DELETE FROM board WHERE id = '$boardId'\";")
      document.write("mysql_query($query, $mysql_access);")
      document.write("$updateStatus = \"News Deleted Successfully.\";")
      document.write("?>")
      }
      else
      {
      }
      </script>

      its this thats throwing the error
      document.write("<?")
      If I take that out (and also the ?>)

      it prints out the code.

        <script type="text/javascript">
            var areYouSure=confirm("Are you sure you want to delete?")
            if (areYouSure==true) {
                document.write("<? code here?>")
            }
        </script>
        

        Okay I see what's happening. javascript is client side and php is server side, what you have to do for something like this is:

        1) Bake the button to delete entries go to a javascript that looks similar to the above.

        2) Make the form point to the script that deletes a post and pass it the variables in hidden form fields to delete a post.

        3) Change the document.write above into document.forms[x].submit(). Where x is the number of forms that appear in the html code before the form you wish to submit. Therefor is you have two forms on your page and you wish to submit the one that appears first in the code x is 0, if you wish to submit the one that appears second in the code x is 1 and so on.

          Write a Reply...