Reply to Re: Function execution before page reload

Your name:

Reply:


Posted by Schmidty on 01/28/07 07:47

Thanks Jerry for the reply. I made a mistake in the variable
"$_SERVER['HTTP_SELF']" in my previous posts, it should be
$_SERVER['PHP_SELF'].
I realize that the html page is static and that the browser does not
communicate with the PHP script.

When a user who updates a database the FORM in the PHP script will
have 'action' set to load a $_SERVER['PHP_SELF'];

Example of 'updatedb.php'
=======================================================================
========

<?php
// updatedb.php
$nu = new userFunction();

echo "<form action=\"$_SERVER['PHP_SELF']\" method='post'><input
type='text' name='name' /><input type='submit' name='update'
value='UPDATE DB' /></form>";

if (isset($_POST['update'])){
$nu->updateDBFunction($_POST['name']);
print "DB UPDATED<br />";

}

?>

End Example
=======================================================================
==================

In the short example above does the script execute the function BEFORE
it reloads the $_SERVER['PHP_SELF'] variable?

Schmidty




On Jan 26, 7:06 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Schmidty wrote:
> > Okay...I have another 'newbie' question;
>
> > I have a function that loads a page and the action is
> > $_SERVER['HTTP_SELF'];
> > In the form that is in a function(method?) within a class a variable
> > is passed back to a mysqli connection and database and updates the
> > database.
> > The problem is that when the page is reloaded it does not show the
> > updated information in the database with the $_SERVER['HTTP_SELF']. Why
> > is the page loaded with the same information? Is it cached from the
> > browser? Is there a way to have the functions execute before the
> > $_SERVER['HTTP_SELF'] action executes?
>
> > Example code ======================================
> > // Show info of users not updated
> > echo "<form action='".$_SERVER['PHP_SELF']."' method='post'><table
> > style=\"font: 14px solid #000000; border: 2px solid #CCC000;\">";
> > echo "<tr><td colspan='2' style=\"background: #C0C0C5; text-align:
> > center; font: 18px solid #000000;\">Credit Card
> > Applications</td></tr>";
> > echo "<tr><td colspan='2' style=\"background: #FFFFE0; text-align:
> > left; font: 12px solid #000000;\">New Applications In Database Needing
> > Approval:</td></tr>";
> > echo "<tr><tr><td colspan='2' style=\"border: 2px solid #000000;
> > width: 100%;\">";
>
> > if ($result->num_rows == 0) {echo "NO NEW APPLICATIONS<br />";}
> > while($row = $result->fetch_assoc()){
>
> > echo "<input type='checkbox' name='perinfo[]'
> > value='".$row['userID']."' >".$row['userID']." : ".$row['username']." -
> > ".$row['recdate']."<br />";
> > } // end while
> > echo "</td></tr><tr>";
> > echo "<td align=\"center\"><input style=\"font: 10px solid
> > #000000;\" type=\"submit\" value=\"UPDATE INFO\" name='updatedb'
> > /></td><td style=\"text-align: center;\"><input type=\"reset\"
> > style=\"font: 10px solid #000000;\" value=\"RESET CHOICES\"
> > /></td></tr></form></table>";
> > $result->free();
>
> > } // end function
>
> > public function dbConnect(){
> > include('dbconn.php');
> > $mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);
>
> > if (mysqli_connect_errno()){ printf("Can't connect to MySQL Server.
> > Errorcode: %s\n", mysqli_connect_error());
> > exit;
> > } // end if
> > return $this->mysqli=$mysqli;
>
> > } // end function
> > End Example Code ===================================================
>
> > Thanks for the help!
>
> > SchmidtySchmidty,
>
> Where are you updating the database? And where are you retrieving the
> values?
>
> PHP is server-side. ALL code is executed before the page is sent to the
> browser. Interaction between PHP and the browser is one-way - the PHP
> sends the page and terminates. There isn't any interaction between the
> browser and the PHP code (other than to load a new page).
>
> When they click on the submit button for the form, the browser requests
> the page identified in your FORM statement. Since it is the same page,
> all of the PHP code is executed again.
>
> But you didn't show most of your code so there's no way to determine
> what might be going on.
>
> And no, you don't need AJAX or similar for this to work. Straight PHP
> works great.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -- Show quoted text -

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация