PHP page get executed twice

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marcel

    PHP page get executed twice

    I have a problem with a PHP page that seems to get executed twice.

    I am running PHP5 ISAPI on 2003 server.

    The script is a PHP page with a form. When the form is submitted one record
    have to be inserted in the database but when i look at the database after
    submitting the form there are two(!) records inserted so it looks like the
    script is executed twice.

    Can this be a proxy-setting or an ISA`server related subject???

    Anyone ever experienced similair problems?

    Marcel


  • Erwin Moller

    #2
    Re: PHP page get executed twice

    Marcel wrote:
    [color=blue]
    > I have a problem with a PHP page that seems to get executed twice.
    >
    > I am running PHP5 ISAPI on 2003 server.
    >
    > The script is a PHP page with a form. When the form is submitted one
    > record have to be inserted in the database but when i look at the database
    > after submitting the form there are two(!) records inserted so it looks
    > like the script is executed twice.[/color]

    Hi Marcel,

    Sorry to say, but this is most likely a problem in your code, not in the
    server/webserver/PHP.

    Are you maybe sending the form to the same page that produces the form?
    If so, are you sure your checks for a posting and the following DB-inserts
    are working as expected?

    Maybe add a few echo's before inserting and check if they show up
    unexpectedly?

    And you can always show us some code (preferable stripped down to the core).
    [color=blue]
    >
    > Can this be a proxy-setting or an ISA`server related subject???[/color]

    I don't think so, but then again, I don't know what an ISAserver is.
    [color=blue]
    >
    > Anyone ever experienced similair problems?[/color]

    Only under Tomcat with Java (which creates a complete copy of the webapp for
    purposes still mysterious to me), never with PHP under *nix or ISS.
    [color=blue]
    >
    > Marcel[/color]

    Regards,
    Erwin Moller

    Comment

    • lorento

      #3
      Re: PHP page get executed twice

      Marcel wrote:[color=blue]
      > I have a problem with a PHP page that seems to get executed twice.[/color]

      Have you check your own code? Maybe you execute twice.

      regards,
      Lorento
      --

      http://www.padbuilder.com , http://www.immersivelounge.com

      Comment

      • Marcel

        #4
        Re: PHP page get executed twice


        "Erwin Moller"
        <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> schreef in
        bericht news:447ee31b$0 $31644$e4fe514c @news.xs4all.nl ...[color=blue]
        > Marcel wrote:
        >[color=green]
        >> I have a problem with a PHP page that seems to get executed twice.
        >>
        >> I am running PHP5 ISAPI on 2003 server.
        >>
        >> The script is a PHP page with a form. When the form is submitted one
        >> record have to be inserted in the database but when i look at the
        >> database
        >> after submitting the form there are two(!) records inserted so it looks
        >> like the script is executed twice.[/color]
        >
        > Hi Marcel,
        >
        > Sorry to say, but this is most likely a problem in your code, not in the
        > server/webserver/PHP.[/color]

        Yeah, maybe you are right but i am an experienced coder and i have been
        searching for 2 days now where this is coming from.

        I will post my code but it's kind of advanced PHP5 OOP stuff.
        [color=blue]
        >
        > Are you maybe sending the form to the same page that produces the form?[/color]

        Yes i am posting to the same page. So the page takes care of the database
        activity too
        [color=blue]
        > If so, are you sure your checks for a posting and the following DB-inserts
        > are working as expected?[/color]

        I have made a SQL class that takes care of the inserts and updates in the MS
        SQL Server database
        [color=blue]
        >
        > Maybe add a few echo's before inserting and check if they show up
        > unexpectedly?[/color]

        I have put a mail() in my page to check and i receive a testmail twice... so
        that makes me again think the page is executed twice.......
        [color=blue]
        >
        > And you can always show us some code (preferable stripped down to the
        > core).
        >[color=green]
        >>
        >> Can this be a proxy-setting or an ISA`server related subject???[/color]
        >
        > I don't think so, but then again, I don't know what an ISAserver is.
        >[color=green]
        >>
        >> Anyone ever experienced similair problems?[/color]
        >
        > Only under Tomcat with Java (which creates a complete copy of the webapp
        > for
        > purposes still mysterious to me), never with PHP under *nix or ISS.
        >[color=green]
        >>
        >> Marcel[/color]
        >
        > Regards,
        > Erwin Moller[/color]


        Comment

        • Marcel

          #5
          Re: PHP page get executed twice

          ### mainpage

          <?php
          #error_reportin g(E_ALL); // alle fouten weergeven
          #error_reportin g(0); // geen fouten weergeven
          error_reporting (E_ALL ^ E_NOTICE); // alle fouten behalve notices weergeven

          header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
          header("Expires : Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past

          # database connection
          require_once(". ./Connections/connect_communi cation.php");

          # mssql_escape function
          require_once(". ./php_functions/mssql_escape.ph p");

          #
          require_once(". ./php_functions/validator.php") ;

          #
          require_once(". ./php_functions/sql.php");

          $uploaddir = 'C:/Inetpub/domain.com/newsletters/uploaded_images/';


          mail("info@medi aquest.nl","Tes t Newsletters",$_ SERVER['HTTP_REFERER'].' -
          '.$_SERVER['REMOTE_HOST'].' - '.$_SERVER['REQUEST_URI']);


          function img_exists($fil ename_to_check) {

          $SQLcheck = "SELECT id FROM com_images WHERE img_original_na me =
          '".trim($filena me_to_check)."' ";

          #echo '<hr />'.$SQLcheck.'< hr />';

          $RESULTcheck = mssql_query($SQ Lcheck);

          if(mssql_num_ro ws($RESULTcheck ) > 0) {
          return true;
          } else {
          return false;
          }

          }

          if($_POST['Submit']) {

          rule(!$_POST['nwi_name'],
          "You did not fill in a name for this newsitem");

          /*
          rule(isset($_FI LES['nwi_image1']['name']) &&
          img_exists($_FI LES['nwi_image1']['name']),
          "The filename of Image 1 that you are trying to upload allready exists");

          rule(isset($_FI LES['nwi_image2']['name']) &&
          img_exists($_FI LES['nwi_image2']['name']),
          "The filename of Image 2 that you are trying to upload allready exists");

          rule(isset($_FI LES['nwi_image3']['name']) &&
          img_exists($_FI LES['nwi_image3']['name']),
          "The filename of Image 3 that you are trying to upload allready exists");

          rule(isset($_FI LES['nwi_image4']['name']) &&
          img_exists($_FI LES['nwi_image4']['name']),
          "The filename of Image 4 that you are trying to upload allready exists");
          */

          # validation of userinput
          if(getError()) {

          # zo ja error message toekennen aan $err_msg
          $err_msg = getError();

          # leeg maken array validations
          clearValidation s();

          $tmp_nwi_name = $_POST['nwi_name'];
          $tmp_nwi_descri ption = $_POST['nwi_descriptio n'];

          $tmp_nwi_headin g = $_POST['nwi_heading'];

          $tmp_nwi_subhea ding1 = $_POST['nwi_subheading 1'];
          $tmp_nwi_image1 = $_POST['nwi_image1'];
          $tmp_nwi_alignm ent1 = $_POST['nwi_alignment1 '];
          $tmp_nwi_text1 = $_POST['nwi_text1'];

          $tmp_nwi_subhea ding2 = $_POST['nwi_subheading 2'];
          $tmp_nwi_image2 = $_POST['nwi_image2'];
          $tmp_nwi_alignm ent2 = $_POST['nwi_alignment2 '];
          $tmp_nwi_text2 = $_POST['nwi_text2'];

          $tmp_nwi_subhea ding3 = $_POST['nwi_subheading 3'];
          $tmp_nwi_image3 = $_POST['nwi_image3'];
          $tmp_nwi_alignm ent3 = $_POST['nwi_alignment3 '];
          $tmp_nwi_text3 = $_POST['nwi_text3'];

          $tmp_nwi_subhea ding4 = $_POST['nwi_subheading 4'];
          $tmp_nwi_image4 = $_POST['nwi_image4'];
          $tmp_nwi_alignm ent4 = $_POST['nwi_alignment4 '];
          $tmp_nwi_text4 = $_POST['nwi_text4'];


          } else {
          # all userinput proofed ok, let's write data to database

          #echo '<hr />userinput ok!!!<hr />';

          clearValidation s();

          # indien er images geupload worden
          # img 1
          if($_FILES['nwi_image1']['name']) {

          $tsql_img1 = new sql('com_images ');

          $tsql_img1->add("img_origi nal_name",$_FIL ES['nwi_image1']['name']);
          $tsql_img1->add("img_tmp_n ame",$_FILES['nwi_image1']['tmp_name']);
          $tsql_img1->add("img_type" ,$_FILES['nwi_image1']['type']);
          if(GetImageSize ($_FILES['nwi_image1']['tmp_name'])) {

          $img_dimensions = GetImageSize($_ FILES['nwi_image1']['tmp_name']);

          $tsql_img1->add("img_width ",$img_dimensio ns[0]);
          $tsql_img1->add("img_heigh t",$img_dimensi ons[1]);

          }
          $tsql_img1->add("img_bytes ",$_FILES['nwi_image1']['size']);

          # C:\Inetpub\doma in.com\newslett ers\uploaded_im ages

          if(move_uploade d_file($_FILES['nwi_image1']['tmp_name'],
          $uploaddir.$_FI LES["nwi_image1 "]["name"])) {

          $tsql_img1->add("img_syste m_name","http://www.domain.com/newsletters/uploaded_images/".$_FILES["nwi_image1 "]["name"]);

          }

          $tsql_img1->insert();

          $nwi_image1_id = $tsql_img1->getLastID();

          unset($tsql_img 1);

          }

          # indien er images geupload worden
          # img 2
          if($_FILES['nwi_image2']['name']) {

          $tsql_img2 = new sql('com_images ');

          $tsql_img2->add("img_origi nal_name",$_FIL ES['nwi_image2']['name']);
          $tsql_img2->add("img_tmp_n ame",$_FILES['nwi_image2']['tmp_name']);
          $tsql_img2->add("img_type" ,$_FILES['nwi_image2']['type']);
          if(GetImageSize ($_FILES['nwi_image2']['tmp_name'])) {

          $img_dimensions = GetImageSize($_ FILES['nwi_image2']['tmp_name']);

          $tsql_img2->add("img_width ",$img_dimensio ns[0]);
          $tsql_img2->add("img_heigh t",$img_dimensi ons[1]);

          }
          $tsql_img2->add("img_bytes ",$_FILES['nwi_image2']['size']);

          # C:\Inetpub\doma in.com\newslett ers\uploaded_im ages

          if(move_uploade d_file($_FILES['nwi_image2']['tmp_name'],
          $uploaddir.$_FI LES["nwi_image2 "]["name"])) {

          $tsql_img2->add("img_syste m_name","http://www.domain.com/newsletters/uploaded_images/".$_FILES["nwi_image2 "]["name"]);

          }

          $tsql_img2->insert();

          $nwi_image2_id = $tsql_img2->getLastID();

          unset($tsql_img 2);

          }

          # indien er images geupload worden
          # img 3
          if($_FILES['nwi_image3']['name']) {

          $tsql_img3 = new sql('com_images ');

          $tsql_img3->add("img_origi nal_name",$_FIL ES['nwi_image3']['name']);
          $tsql_img3->add("img_tmp_n ame",$_FILES['nwi_image3']['tmp_name']);
          $tsql_img3->add("img_type" ,$_FILES['nwi_image3']['type']);
          if(GetImageSize ($_FILES['nwi_image3']['tmp_name'])) {

          $img_dimensions = GetImageSize($_ FILES['nwi_image3']['tmp_name']);

          $tsql_img3->add("img_width ",$img_dimensio ns[0]);
          $tsql_img3->add("img_heigh t",$img_dimensi ons[1]);

          }
          $tsql_img3->add("img_bytes ",$_FILES['nwi_image3']['size']);

          # C:\Inetpub\doma in.com\newslett ers\uploaded_im ages

          if(move_uploade d_file($_FILES['nwi_image3']['tmp_name'],
          $uploaddir.$_FI LES["nwi_image3 "]["name"])) {

          $tsql_img3->add("img_syste m_name","http://www.domain.com/newsletters/uploaded_images/".$_FILES["nwi_image3 "]["name"]);

          }

          $tsql_img3->insert();

          $nwi_image3_id = $tsql_img3->getLastID();

          unset($tsql_img 3);

          }

          # indien er images geupload worden
          # img 4
          if($_FILES['nwi_image4']['name']) {

          $tsql_img4 = new sql('com_images ');

          $tsql_img4->add("img_origi nal_name",$_FIL ES['nwi_image4']['name']);
          $tsql_img4->add("img_tmp_n ame",$_FILES['nwi_image4']['tmp_name']);
          $tsql_img4->add("img_type" ,$_FILES['nwi_image4']['type']);
          if(GetImageSize ($_FILES['nwi_image4']['tmp_name'])) {

          $img_dimensions = GetImageSize($_ FILES['nwi_image4']['tmp_name']);

          $tsql_img4->add("img_width ",$img_dimensio ns[0]);
          $tsql_img4->add("img_heigh t",$img_dimensi ons[1]);

          }
          $tsql_img4->add("img_bytes ",$_FILES['nwi_image4']['size']);

          # C:\Inetpub\doma in.com\newslett ers\uploaded_im ages

          if(move_uploade d_file($_FILES['nwi_image4']['tmp_name'],
          $uploaddir.$_FI LES["nwi_image4 "]["name"])) {

          $tsql_img4->add("img_syste m_name","http://www.domain.com/newsletters/uploaded_images/".$_FILES["nwi_image4 "]["name"]);

          }

          $tsql_img4->insert();

          $nwi_image4_id = $tsql_img4->getLastID();

          unset($tsql_img 4);

          }




          $tsql = new sql('com_newsit ems');


          $tsql->add("nwi_name" ,$_POST['nwi_name']);
          $tsql->add("nwi_descr iption",$_POST['nwi_descriptio n']);

          $tsql->add("nwi_headi ng",$_POST['nwi_heading']);

          $tsql->add("nwi_subhe ading1",$_POST['nwi_subheading 1']);
          if($_FILES['nwi_image1']['name']) {
          $tsql->add("nwi_image 1",$nwi_image1_ id);
          $tsql->add("nwi_align ment1",$_POST['nwi_alignment1 ']);
          } else {

          if(!$_POST['nwi_image1_del ']) {
          $tsql->exclude("nwi_i mage1");
          }

          }
          $tsql->add("nwi_text1 ",$_POST['nwi_text1']);

          $tsql->add("nwi_subhe ading2",$_POST['nwi_subheading 2']);
          if($_FILES['nwi_image2']['name']) {
          $tsql->add("nwi_image 2",$nwi_image2_ id);
          $tsql->add("nwi_align ment2",$_POST['nwi_alignment2 ']);
          } else {

          if(!$_POST['nwi_image2_del ']) {
          $tsql->exclude("nwi_i mage2");
          }

          }
          $tsql->add("nwi_text2 ",$_POST['nwi_text2']);

          $tsql->add("nwi_subhe ading3",$_POST['nwi_subheading 3']);
          if($_FILES['nwi_image3']['name']) {
          $tsql->add("nwi_image 3",$nwi_image3_ id);
          $tsql->add("nwi_align ment3",$_POST['nwi_alignment3 ']);
          } else {

          if(!$_POST['nwi_image3_del ']) {
          $tsql->exclude("nwi_i mage3");
          }

          }
          $tsql->add("nwi_text3 ",$_POST['nwi_text3']);

          $tsql->add("nwi_subhe ading4",$_POST['nwi_subheading 4']);
          if($_FILES['nwi_image4']['name']) {
          $tsql->add("nwi_image 4",$nwi_image4_ id);
          $tsql->add("nwi_align ment4",$_POST['nwi_alignment4 ']);
          } else {

          if(!$_POST['nwi_image4_del ']) {
          $tsql->exclude("nwi_i mage4");
          }

          }
          $tsql->add("nwi_text4 ",$_POST['nwi_text4']);


          $tsql->exclude("id" );
          $tsql->exclude("nwi_d ate_created");


          $tsql->update("id",$_ POST['id']);

          unset($tsql);

          unset($_FILES);

          header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
          header("Expires : Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
          header("Locatio n:newsitems.php ");


          #echo $tsql->getSQLupdate() ;



          }

          } else {

          $SQL = "SELECT * FROM com_newsitems WHERE id = ".$_GET['id'];

          $RESULT = mssql_query($SQ L);

          $RECORD = mssql_fetch_arr ay($RESULT);

          $tmp_nwi_name = $RECORD['nwi_name'];
          $tmp_nwi_descri ption = $RECORD['nwi_descriptio n'];

          $tmp_nwi_headin g = $RECORD['nwi_heading'];

          $tmp_nwi_subhea ding1 = $RECORD['nwi_subheading 1'];
          $tmp_nwi_image1 = $RECORD['nwi_image1'];


          if($RECORD['nwi_image1']) {

          $SQLimg1 = "SELECT img_original_na me FROM com_images WHERE id =
          ".$RECORD['nwi_image1'];

          $RESULTimg1 = mssql_query($SQ Limg1);

          if(mssql_num_ro ws($RESULTimg1) > 0) {

          $RECORDimg1 = mssql_fetch_arr ay($RESULTimg1) ;

          $nwi_image1_nam e = $RECORDimg1['img_original_n ame'];

          }

          }

          $tmp_nwi_alignm ent1 = $RECORD['nwi_alignment1 '];
          $tmp_nwi_text1 = $RECORD['nwi_text1'];

          $tmp_nwi_subhea ding2 = $RECORD['nwi_subheading 2'];
          $tmp_nwi_image2 = $RECORD['nwi_image2'];

          if($RECORD['nwi_image2']) {

          $SQLimg2 = "SELECT img_original_na me FROM com_images WHERE id =
          ".$RECORD['nwi_image2'];

          $RESULTimg2 = mssql_query($SQ Limg2);

          if(mssql_num_ro ws($RESULTimg2) > 0) {

          $RECORDimg2 = mssql_fetch_arr ay($RESULTimg2) ;

          $nwi_image2_nam e = $RECORDimg2['img_original_n ame'];

          }

          }

          $tmp_nwi_alignm ent2 = $RECORD['nwi_alignment2 '];
          $tmp_nwi_text2 = $RECORD['nwi_text2'];

          $tmp_nwi_subhea ding3 = $RECORD['nwi_subheading 3'];
          $tmp_nwi_image3 = $RECORD['nwi_image3'];

          if($RECORD['nwi_image3']) {

          $SQLimg3 = "SELECT img_original_na me FROM com_images WHERE id =
          ".$RECORD['nwi_image3'];

          $RESULTimg3 = mssql_query($SQ Limg3);

          if(mssql_num_ro ws($RESULTimg3) > 0) {

          $RECORDimg3 = mssql_fetch_arr ay($RESULTimg3) ;

          $nwi_image3_nam e = $RECORDimg3['img_original_n ame'];

          }

          }

          $tmp_nwi_alignm ent3 = $RECORD['nwi_alignment3 '];
          $tmp_nwi_text3 = $RECORD['nwi_text3'];

          $tmp_nwi_subhea ding4 = $RECORD['nwi_subheading 4'];
          $tmp_nwi_image4 = $RECORD['nwi_image4'];

          if($RECORD['nwi_image4']) {

          $SQLimg4 = "SELECT img_original_na me FROM com_images WHERE id =
          ".$RECORD['nwi_image4'];

          $RESULTimg4 = mssql_query($SQ Limg4);

          if(mssql_num_ro ws($RESULTimg4) > 0) {

          $RECORDimg4 = mssql_fetch_arr ay($RESULTimg4) ;

          $nwi_image4_nam e = $RECORDimg4['img_original_n ame'];

          }

          }

          $tmp_nwi_alignm ent4 = $RECORD['nwi_alignment4 '];
          $tmp_nwi_text4 = $RECORD['nwi_text4'];

          $tmp_id = $_GET['id'];

          }

          ?>

          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          <title>domain.c om CMS Newsletters</title>
          <link href="styles/newslettercms.c ss" rel="stylesheet " type="text/css">
          </head>
          <body vlink="#000066" alink="#FF3300" >
          <a name="Top"></a>
          <form action="test2.p hp" method="post" enctype="multip art/form-data"
          name="form1">
          <input type="hidden" name="id" value="<?php echo $tmp_id; ?>">
          <table width="748" border="0" align="center" cellpadding="1" cellspacing="1"
          bgcolor="#00387 5">
          <tr>
          <td width="744" bgcolor="#fffff f">
          <table width="744" border="0" cellspacing="0" cellpadding="0" >
          <tr>
          <td width="166" height="79">
          <div align="center"> <a href="http://www.domain.com" ><img
          src="images/mv-logo.gif" alt="domain.com " width="153" height="50"
          border="0"></a></div>
          </td>
          <td width="578" align="right">< img src="images/header-1.jpg"
          alt="domain.com " width="550" height="79"></td>
          </tr>
          <tr>
          <td colspan="2" bgcolor="#00387 5">
          <table width="744" border="0" cellspacing="0" cellpadding="4" >
          <tr>
          <td width="468"><fo nt color="#ffffff" face="Verdana, Arial, Helvetica,
          sans-serif" size="2"><stron g>domain.com
          CMS Newsletters</strong></font></td>
          <td width="260" align="right">< font color="#ffffff" face="Verdana, Arial,
          Helvetica, sans-serif" size="2">Welcom e
          administrator</font></td>
          </tr>
          </table>
          </td>
          </tr>
          </table>
          <table width="744" border="0" cellspacing="0" cellpadding="0" >
          <tr>
          <td width="748" valign="top">
          <table width="744" border="0" align="center" cellpadding="4"
          cellspacing="0" >
          <tr>
          <td valign="top" align="center" bgcolor="#f1f1f 1"><font color="#003875"
          face="Arial, Helvetica, sans-serif" size="2"> <strong>|</strong> <a
          href="emailaddr esses.php">View/manage
          e-mail adressess</a> <strong>|</strong> <a
          href="newslette rs.php">View/manage newsletters</a> <strong>|</strong> <a
          href="newsitems .php">View/manage
          newsitems</a> <strong>|</strong> <a href="#">View userhistory</a>
          <strong>|</strong> </font></td>
          </tr>
          </table>
          <br>
          <table width="736" border="0" align="center" cellpadding="2"
          cellspacing="0" >
          <tr>
          <td width="732"><fo nt color="#003875" face="Arial, Helvetica, sans-serif"
          size="3"><stron g>Edit newsitem </strong></font></td>
          </tr>
          <tr>
          <td align="right">< font color="#000000" face="Arial, Helvetica, sans-serif"
          size="2"><a href="addnewsit em.php">create new newsitem</a>
          &raquo;</font></td>
          </tr>
          <?php
          if($err_msg) {
          ?>
          <tr>
          <td><font color="#FF0000" face="Arial, Helvetica, sans-serif"
          size="2"><stron g><?php echo $err_msg; ?></strong></font></td>
          </tr>
          <?php
          }
          ?>
          </table>
          <font face="Arial, Helvetica, sans-serif">
          <table class="table3">
          <tr>
          <td>Newsitem name</td>
          <td>
          <input name="nwi_name" type="text" class="nwi_titl e" id="nwi_name"
          value="<?php echo $tmp_nwi_name; ?>">
          </td>
          </tr>
          <tr>
          <td>Newsitem description</td>
          <td>
          <textarea name="nwi_descr iption" id="nwi_descrip tion" cols="35"
          rows="6"><?php echo $tmp_nwi_descri ption; ?></textarea>
          </td>
          </tr>

          <tr>
          <td colspan="2"><hr /></td>
          </tr>
          <tr>
          <td>Heading</td>
          <td>
          <input name="nwi_headi ng" type="text" class="nwl_nwi_ name" id="nwi_heading "
          value="<?php echo $tmp_nwi_headin g; ?>">
          </td>
          </tr>
          <tr>
          <td colspan="2"><hr /></td>
          </tr>

          <!-- 1 -->
          <tr>
          <td>Subheadin g 1</td>
          <td>
          <input name="nwi_subhe ading1" type="text" class="nwl_nwi_ name"
          id="nwi_subhead ing1" value="<?php echo $tmp_nwi_subhea ding1; ?>">
          </td>
          </tr>
          <tr>
          <td>&nbsp;</td>
          <td>
          <?php echo $nwi_image1_nam e; ?><input name="nwi_image 1_del" type="checkbox"
          id="nwi_image1_ del" value="<?php echo $nwi_image1_nam e; ?>">
          </td>
          </tr>
          <tr>
          <td>Image 1</td>
          <td>
          <input name="nwi_image 1" type="file" class="nwl_nwi_ name" id="nwi_image1 "
          value="<?php echo $tmp_nwi_image1 ; ?>">
          </td>
          </tr>
          <tr>
          <td>Horzontal alignment 1</td>
          <td>
          <input name="nwi_align ment1" type="radio" value="L" <?php
          if($tmp_nwi_ali gnment1 == 'L') {echo 'checked';} ?>> Left
          <input name="nwi_align ment1" type="radio" value="C" <?php
          if($tmp_nwi_ali gnment1 == 'C') {echo 'checked';} ?>> Center
          <input name="nwi_align ment1" type="radio" value="R" <?php
          if($tmp_nwi_ali gnment1 == 'R') {echo 'checked';} ?>> Right
          </td>
          </tr>
          <tr>
          <td>Text 1</td>
          <td>
          <textarea name="nwi_text1 " id="nwi_text1" cols="35" rows="6"><?php echo
          $tmp_nwi_text1; ?></textarea>
          </td>
          </tr>
          <tr>
          <td colspan="2"><hr /></td>
          </tr>

          <!-- 2 -->
          <tr>
          <td>Subheadin g 2</td>
          <td>
          <input name="nwi_subhe ading2" type="text" class="nwl_nwi_ name"
          id="nwi_subhead ing2" value="<?php echo $tmp_nwi_subhea ding2; ?>">
          </td>
          </tr>
          <tr>
          <td>&nbsp;</td>
          <td>
          <?php echo $nwi_image2_nam e; ?><input name="nwi_image 2_del" type="checkbox"
          id="nwi_image2_ del" value="<?php echo $nwi_image2_nam e; ?>">
          </td>
          </tr>
          <tr>
          <td>Image 2</td>
          <td>
          <input name="nwi_image 2" type="file" class="nwl_nwi_ name" id="nwi_image2 "
          value="<?php echo $tmp_nwi_image2 ; ?>">
          </td>
          </tr>
          <tr>
          <td>Horzontal alignment 2</td>
          <td>
          <input name="nwi_align ment2" type="radio" value="L" <?php
          if($tmp_nwi_ali gnment2 == 'L') {echo 'checked';} ?>> Left
          <input name="nwi_align ment2" type="radio" value="C" <?php
          if($tmp_nwi_ali gnment2 == 'C') {echo 'checked';} ?>> Center
          <input name="nwi_align ment2" type="radio" value="R" <?php
          if($tmp_nwi_ali gnment2 == 'R') {echo 'checked';} ?>> Right
          </td>
          </tr>
          <tr>
          <td>Text 2</td>
          <td>
          <textarea name="nwi_text2 " id="nwi_text2" cols="35" rows="6"><?php echo
          $tmp_nwi_text2; ?></textarea>
          </td>
          </tr>
          <tr>
          <td colspan="2"><hr /></td>
          </tr>


          <!-- 3 -->
          <tr>
          <td>Subheadin g 3</td>
          <td>
          <input name="nwi_subhe ading3" type="text" class="nwl_nwi_ name"
          id="nwi_subhead ing3" value="<?php echo $tmp_nwi_subhea ding3; ?>">
          </td>
          </tr>
          <tr>
          <td>&nbsp;</td>
          <td>
          <?php echo $nwi_image3_nam e; ?><input name="nwi_image 3_del" type="checkbox"
          id="nwi_image3_ del" value="<?php echo $nwi_image3_nam e; ?>">
          </td>
          </tr>
          <tr>
          <td>Image 3</td>
          <td>
          <input name="nwi_image 3" type="file" class="nwl_nwi_ name" id="nwi_image3 "
          value="<?php echo $tmp_nwi_image3 ; ?>">
          </td>
          </tr>
          <tr>
          <td>Horzontal alignment 3</td>
          <td>
          <input name="nwi_align ment3" type="radio" value="L" <?php
          if($tmp_nwi_ali gnment3 == 'L') {echo 'checked';} ?>> Left
          <input name="nwi_align ment3" type="radio" value="C" <?php
          if($tmp_nwi_ali gnment3 == 'C') {echo 'checked';} ?>> Center
          <input name="nwi_align ment3" type="radio" value="R" <?php
          if($tmp_nwi_ali gnment3 == 'R') {echo 'checked';} ?>> Right
          </td>
          </tr>
          <tr>
          <td>Text 3</td>
          <td>
          <textarea name="nwi_text3 " id="nwi_text3" cols="35" rows="6"><?php echo
          $tmp_nwi_text3; ?></textarea>
          </td>
          </tr>
          <tr>
          <td colspan="2"><hr /></td>
          </tr>



          <!-- 4 -->
          <tr>
          <td>Subheadin g 4</td>
          <td>
          <input name="nwi_subhe ading4" type="text" class="nwl_nwi_ name"
          id="nwi_subhead ing4" value="<?php echo $tmp_nwi_subhea ding4; ?>">
          </td>
          </tr>
          <tr>
          <td>&nbsp;</td>
          <td>
          <?php echo $nwi_image4_nam e; ?><input name="nwi_image 4_del" type="checkbox"
          id="nwi_image4_ del" value="<?php echo $nwi_image4_nam e; ?>">
          </td>
          </tr>
          <tr>
          <td>Image 4</td>
          <td>
          <input name="nwi_image 4" type="file" class="nwl_nwi_ name" id="nwi_image4 "
          value="<?php echo $tmp_nwi_image4 ; ?>">
          </td>
          </tr>
          <tr>
          <td>Horzontal alignment 4</td>
          <td>
          <input name="nwi_align ment4" type="radio" value="L" <?php
          if($tmp_nwi_ali gnment4 == 'L') {echo 'checked';} ?>> Left
          <input name="nwi_align ment4" type="radio" value="C" <?php
          if($tmp_nwi_ali gnment4 == 'C') {echo 'checked';} ?>> Center
          <input name="nwi_align ment4" type="radio" value="R" <?php
          if($tmp_nwi_ali gnment4 == 'R') {echo 'checked';} ?>> Right
          </td>
          </tr>
          <tr>
          <td>Text 4</td>
          <td>
          <textarea name="nwi_text4 " id="nwi_text4" cols="35" rows="6"><?php echo
          $tmp_nwi_text4; ?></textarea>
          </td>
          </tr>
          <tr>
          <td colspan="2"><hr /></td>
          </tr>

          <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          </tr>
          <tr>
          <td>&nbsp;</td>
          <td>
          <input type="submit" name="Submit" value="gereed &raquo;">
          </td>
          </tr>
          </table>
          </font> <br>
          <br>
          </td>
          </tr>
          <tr>
          <td bgcolor="#008C9 A">&nbsp;</td>
          </tr>
          </table>
          </td>
          </tr>
          </table>
          </form>
          </body>
          </html>


          ### sql class

          # class column om info over columns in op te slaan
          class column {

          var $name; # columnname
          var $xtype; # datatype
          var $colid; # positie
          var $isnullable; # of er null in deze column mag staan
          var $newval; # value die geinsert of updated moet worden

          }

          # class sql
          class sql {

          var $table; # de table waar dit sql-object betrekking op heeft
          var $columns = array(); # de columns in deze table, in deze array worden
          alle columns uit de tabel opgeslagen, per column wordt een column-object
          aangemaakt die diverse info bevat over de column
          var $excluded_colum ns = array();


          # default constructor, neemt als argument de tabel waarop dit sql object
          betrekking heeft
          public function __construct($ta ble) {

          $this->table = $table;

          # sql statement om info over columns in deze tabel te verkrijgen
          $SQLsys = "SELECT syscolumns.name , syscolumns.xtyp e, syscolumns.coli d,
          syscolumns.isnu llable FROM sysobjects INNER JOIN syscolumns ON sysobjects.id
          = syscolumns.id WHERE (sysobjects.nam e = N'".$this->table."')";

          $RESULTsys = mssql_query($SQ Lsys);

          # while-loop om alle info van de diverse columns uit te lezen en toe te
          kennen aan column-objecten
          while($RECORDsy s = mssql_fetch_arr ay($RESULTsys)) {

          # aanmaken nieuw column object
          $tmp_column = new column;

          # toekennen waarden uit database aan net gemaakte column-object
          $tmp_column->name = $RECORDsys['name'];
          $tmp_column->xtype = $RECORDsys['xtype'];
          $tmp_column->colid = $RECORDsys['colid'];
          $tmp_column->isnullable = $RECORDsys['isnullable'];

          # net gemaakte column-object toevoegen aan columns array
          $this->columns[$RECORDsys['name']] = $tmp_column;

          }

          }

          function add($column,$va lue) {

          $this->columns[$column]->newval = "$value";

          }

          # this is the static comparing function
          function cmp_obj($a, $b) {

          $al = $a->colid;

          $bl = $b->colid;

          if ($al == $bl) {

          return 0;

          }

          return ($al > $bl) ? +1 : -1;

          }

          # functie om te kijken of een bepaalde column een string-column of een int
          column is
          function is_stringval($v al_to_check) {

          /*
          61 = datetime
          167 = varchar
          56 = int
          175 = char
          52 = smallint
          106 = decimal
          35 = text
          */

          if($val_to_chec k == 61 || $val_to_check == 167 || $val_to_check == 175 ||
          $val_to_check == 35) {
          return true;
          } else {
          return false;
          }

          }

          function mssql_escape($d ata) {

          if( get_magic_quote s_gpc() ) {
          $data = stripslashes($d ata);
          }

          return str_replace("'" , "''", $data);

          }


          function insert() {

          # op volgorde zetten van columns
          uasort($this->columns,array( "sql", "cmp_obj")) ;

          # start sql-statement
          $SQLins = "";

          $SQLins .= "INSERT INTO ".$this->table." (";

          foreach($this->columns as $value) {
          if(isset($value->newval) && $value->newval != '') {
          $SQLins .= $value->name.",";
          }
          }

          $SQLins = rtrim($SQLins," ,");

          $SQLins .= ") VALUES (";


          foreach($this->columns as $value) {
          if(isset($value->newval) && $value->newval != '') {
          if($this->is_stringval($ value->xtype)) {
          $SQLins .= "'".$this->mssql_escape($ value->newval)."'," ;
          } else {
          $SQLins .= $value->newval.",";
          }

          }
          }

          $SQLins = rtrim($SQLins," ,");

          $SQLins .= ")";

          #echo '<hr />'.$SQLins.'< hr />';

          mssql_query($SQ Lins);

          }

          function exclude($column _name) {

          array_push($thi s->excluded_colum ns,$column_name );

          }

          function
          update($keycolu mn1,$keyval1,$k eycolumn2='',$k eyval2='',$keyc olumn3='',$keyv al3='')
          {

          # op volgorde zetten van columns
          uasort($this->columns,array( "sql", "cmp_obj")) ;

          # start sql-statement
          $SQLupd = "";

          $SQLupd .= "UPDATE ".$this->table." SET ";



          foreach($this->columns as $value) {
          if(!in_array($v alue->name,$this->excluded_colum ns)) {
          if(isset($value->newval) && trim($value->newval) != '') {
          if($this->is_stringval($ value->xtype)) {
          $SQLupd .= $value->name." =
          '".$this->mssql_escape($ value->newval)."'," ;
          } else {
          $SQLupd .= $value->name."= ".$value->newval.",";
          }

          } else {
          $SQLupd .= $value->name."= NULL,";
          }
          }
          }

          $SQLupd = rtrim($SQLupd," ,");

          $SQLupd .= " WHERE ";

          if($keycolumn1) {

          if($this->is_stringval($ this->columns[$keycolumn1]->xtype)) {
          $SQLupd .= $keycolumn1." = '".$keyval1."'" ;
          } else {
          $SQLupd .= $keycolumn1." = ".$keyval1;
          }

          }
          if($keycolumn2) {

          if($this->is_stringval($ this->columns[$keycolumn2]->xtype)) {
          $SQLupd .= " AND ".$keycolum n2." = '".$keyval2."'" ;
          } else {
          $SQLupd .= " AND ".$keycolum n2." = ".$keyval2;
          }

          }
          if($keycolumn3) {

          if($this->is_stringval($ this->columns[$keycolumn3]->xtype)) {
          $SQLupd .= " AND ".$keycolum n3." = '".$keyval3."'" ;
          } else {
          $SQLupd .= " AND ".$keycolum n3." = ".$keyval3;
          }

          }

          #echo $SQLupd;

          mssql_query($SQ Lupd);

          }


          function
          getSQLupdate($k eycolumn1,$keyv al1,$keycolumn2 ='',$keyval2='' ,$keycolumn3='' ,$keyval3='')
          {

          # op volgorde zetten van columns
          uasort($this->columns,array( "sql", "cmp_obj")) ;

          # start sql-statement
          $SQLupd = "";

          $SQLupd .= "UPDATE ".$this->table." SET ";



          foreach($this->columns as $value) {
          if(!in_array($v alue->name,$this->excluded_colum ns)) {
          if(isset($value->newval) && trim($value->newval) != '') {
          if($this->is_stringval($ value->xtype)) {
          $SQLupd .= $value->name." =
          '".$this->mssql_escape($ value->newval)."'," ;
          } else {
          $SQLupd .= $value->name."= ".$value->newval.",";
          }

          } else {
          $SQLupd .= $value->name."= NULL,";
          }
          }
          }

          $SQLupd = rtrim($SQLupd," ,");

          $SQLupd .= " WHERE ";

          if($keycolumn1) {

          if($this->is_stringval($ this->columns[$keycolumn1]->xtype)) {
          $SQLupd .= $keycolumn1." = '".$keyval1."'" ;
          } else {
          $SQLupd .= $keycolumn1." = ".$keyval1;
          }

          }
          if($keycolumn2) {

          if($this->is_stringval($ this->columns[$keycolumn2]->xtype)) {
          $SQLupd .= " AND ".$keycolum n2." = '".$keyval2."'" ;
          } else {
          $SQLupd .= " AND ".$keycolum n2." = ".$keyval2;
          }

          }
          if($keycolumn3) {

          if($this->is_stringval($ this->columns[$keycolumn3]->xtype)) {
          $SQLupd .= " AND ".$keycolum n3." = '".$keyval3."'" ;
          } else {
          $SQLupd .= " AND ".$keycolum n3." = ".$keyval3;
          }

          }

          return $SQLupd;

          }

          function getLastID() {

          $SQLlastid = "SELECT lastid = @@IDENTITY";

          $RESULTlastid = mssql_query($SQ Llastid);

          $RECORDlastid = mssql_fetch_arr ay($RESULTlasti d);

          return $RECORDlastid['lastid'];

          }

          }


          Comment

          • Juan José Gutiérrez de QuevedoPérez

            #6
            Re: PHP page get executed twice

            El Thu, 1 Jun 2006 16:34:40 +0200
            Marcel escribió:
            [color=blue]
            > header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
            > header("Expires : Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the
            > past header("Locatio n:newsitems.php ");[/color]

            just a thing, try to always exit after sending a location header, keep
            in mind that only sending it does NOT end the .php file.

            also if for example you are redirecting someone because they're not
            logged in, the rest of the page WILL be generated, and if you download
            it with wget or curl you'll be able to see without validation.

            header('Locatio n: your-new-location');
            exit;

            don't know if it has any connection to your problem, but change it
            anyway

            --
            Juan José Gutiérrez de Quevedo
            Director Técnico (juanjo@iteisa. com)
            ITEISA (http://www.iteisa.com)
            942544036 - 637447953

            Comment

            • Colin McKinnon

              #7
              Re: PHP page get executed twice

              Marcel wrote:
              [color=blue]
              >
              > "Erwin Moller"
              > <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> schreef in
              > bericht news:447ee31b$0 $31644$e4fe514c @news.xs4all.nl ...[color=green]
              >> Marcel wrote:
              >>[color=darkred]
              >>> I have a problem with a PHP page that seems to get executed twice.
              >>>
              >>> I am running PHP5 ISAPI on 2003 server.[/color]
              >> Hi Marcel,
              >>
              >> Sorry to say, but this is most likely a problem in your code, not in the
              >> server/webserver/PHP.[/color]
              >
              > Yeah, maybe you are right but i am an experienced coder and i have been
              > searching for 2 days now where this is coming from.
              >[/color]

              I was willing to believe you up until I read the code you posted.

              The first place you should have been looking to solve this was in your
              server logs. That would answer the question once and for all as to how many
              times the page was invoked and by whom. You should also get something which
              lets you see the traffic out of your browser - since you seem to be using
              Microsoft server-side, try iehttpheaders.

              If, after the above you still think the code was getting executed twice then
              you should start with 'hello world' and work upwards till you've reproduced
              the problem - then i you still can't explain why, try posting here.

              Some recommended reading:





              [color=blue][color=green][color=darkred]
              >>> Can this be a proxy-setting or an ISA`server related subject???[/color]
              >>
              >> I don't think so, but then again, I don't know what an ISAserver is.
              >>[/color][/color]

              Ah ignorance is bliss. Unfortunately its exactly the kind of the thing to
              expect from ISA^HD so why didn't you try bypassing it, or reading IT's
              logs?

              C.

              Comment

              • Marcel

                #8
                Re: PHP page get executed twice


                "Colin McKinnon"
                <colin.thisisno tmysurname@ntlw orld.deletemeun lessURaBot.com> schreef in
                bericht news:syIfg.6025 $zv2.5125@newsf e4-gui.ntli.net...[color=blue]
                > Marcel wrote:
                >[color=green]
                >>
                >> "Erwin Moller"
                >> <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> schreef
                >> in
                >> bericht news:447ee31b$0 $31644$e4fe514c @news.xs4all.nl ...[color=darkred]
                >>> Marcel wrote:
                >>>
                >>>> I have a problem with a PHP page that seems to get executed twice.
                >>>>
                >>>> I am running PHP5 ISAPI on 2003 server.
                >>> Hi Marcel,
                >>>
                >>> Sorry to say, but this is most likely a problem in your code, not in the
                >>> server/webserver/PHP.[/color]
                >>
                >> Yeah, maybe you are right but i am an experienced coder and i have been
                >> searching for 2 days now where this is coming from.
                >>[/color]
                >
                > I was willing to believe you up until I read the code you posted.
                >
                > The first place you should have been looking to solve this was in your
                > server logs. That would answer the question once and for all as to how
                > many
                > times the page was invoked and by whom. You should also get something
                > which
                > lets you see the traffic out of your browser - since you seem to be using
                > Microsoft server-side, try iehttpheaders.
                >
                > If, after the above you still think the code was getting executed twice
                > then
                > you should start with 'hello world' and work upwards till you've
                > reproduced
                > the problem - then i you still can't explain why, try posting here.
                >
                > Some recommended reading:
                >
                > http://www.dagbladet.no/development/phpcodingstandard/
                > http://www.amazon.com/gp/product/159...lance&n=283155
                > http://www.catb.org/~esr/faqs/smart-questions.html
                >
                >[color=green][color=darkred]
                >>>> Can this be a proxy-setting or an ISA`server related subject???
                >>>
                >>> I don't think so, but then again, I don't know what an ISAserver is.
                >>>[/color][/color]
                >
                > Ah ignorance is bliss. Unfortunately its exactly the kind of the thing to
                > expect from ISA^HD so why didn't you try bypassing it, or reading IT's
                > logs?
                >
                > C.[/color]

                I solved it by replacing

                header("Locatio n:newsitems.php ");

                with a javascript redirect

                <script>
                location='newsi tems.php';
                </script>

                And that solved my problem so i think (i am not sure but....) there is a bug
                in PHP5.1.2 location header function implementation. ....

                Marcel


                Comment

                • Erwin Moller

                  #9
                  Re: PHP page get executed twice

                  Marcel wrote:
                  [color=blue]
                  >
                  > I solved it by replacing
                  >
                  > header("Locatio n:newsitems.php ");
                  >
                  > with a javascript redirect
                  >
                  > <script>
                  > location='newsi tems.php';
                  > </script>
                  >
                  > And that solved my problem so i think (i am not sure but....) there is a
                  > bug in PHP5.1.2 location header function implementation. ....
                  >[/color]

                  No there isn't.
                  I bet you forgot to exit after the header. :P

                  header("Locatio n:newsitems.php ");
                  exit;


                  Regards,
                  Erwin Moller
                  [color=blue]
                  > Marcel[/color]

                  Comment

                  Working...