473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Function execution before page reload

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!

Schmidty

Jan 26 '07 #1
7 3551
A quick follow up question to this posting;

Do I need to use AJAX for this to work? After going over this a few
times here is a simple step-by-step flow of the program;

1. When a user checks a checkbox list of data in database the form
button reloads the page.
2. The PHP script will use an 'if' statement with
'isset($_POST['updatedb'])' and determine the outcome of the
$_POST['data'] in the form. If it is true then it will execute a
function to update the data in the db.
3. In the html the action will execute a $_SERVER['PHP_SELF'] and
reload the page.

The only problem with this whole scenario is that the html is reloading
the page and then the PHP parser runs the 'if' statement. I think this
is what is happening? Anyone have any suggestions?

Schmidty

On Jan 26, 9:42 am, "Schmidty" <schmi...@baronholding.comwrote:
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!

Schmidty
Jan 26 '07 #2
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!

Schmidty
Schmidty,

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.
js*******@attglobal.net
==================
Jan 27 '07 #3
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.netwrote:
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 -
Jan 28 '07 #4
Schmidty wrote:
On Jan 26, 7:06 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>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 -

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

(top posting fixed)

Schmidty,

You need to get over the thought of "reloading the variable...". The
server receives information from the browser and sends html back to the
browser. That's all. There is no "reload $_SERVER['PHP_SELF']" because
it server does not reload anything.

When a request for a page comes in, the web server loads the appropriate
page code. If the page is straight HTML, the code is sent to the
client. If the page includes script code such as PHP, the web server
loads the appropriate interpreter and calls it to execute the code.

The code is executed as it appears in the page. Output from the code is
sent to the webserver. When the page execution is complete, the output
is sent to the client and all resources used by that page are released.

Every page request is handled independently. $_SERVER['PHP_SELF'] is
just a string which refers to this page. You could have 'xyz.php'
instead. It would have the same effect.

In your example, the entire page is executed and sent to the browser.
the script then terminates. When the user presses the 'SUBMIT' button,
the form is submitted back to the the server. Since it is the same
page, the code is executed a second time.

P.S. Please don't top post.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 28 '07 #5
On Jan 28, 5:55 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Schmidty wrote:
On Jan 26, 7:06 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
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 - 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
>
>
>
>

(top posting fixed)

Schmidty,

You need to get over the thought of "reloading the variable...". The
server receives information from the browser and sends html back to the
browser. That's all. There is no "reload $_SERVER['PHP_SELF']" because
it server does not reload anything.

When a request for a page comes in, the web server loads the appropriate
page code. If the page is straight HTML, the code is sent to the
client. If the page includes script code such as PHP, the web server
loads the appropriate interpreter and calls it to execute the code.

The code is executed as it appears in the page. Output from the code is
sent to the webserver. When the page execution is complete, the output
is sent to the client and all resources used by that page are released.

Every page request is handled independently. $_SERVER['PHP_SELF'] is
just a string which refers to this page. You could have 'xyz.php'
instead. It would have the same effect.

In your example, the entire page is executed and sent to the browser.
the script then terminates. When the user presses the 'SUBMIT' button,
the form is submitted back to the the server. Since it is the same
page, the code is executed a second time.

P.S. Please don't top post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Jerry,

Thanks for your help on this. I am still learning the client/server
concepts with PHP as well as OOP so bare with me...

I understand what you have said and it makes sense. How would I update
the page with new information that is sent back from the database via
the server after clicking a 'submit' button? From what you are telling
me then, when the 'submit' button is pressed the script is re-
executed. In a function would I set the 'action' to a new page or use
the $_SERVER['PHP_SELF'] variable? Do I put an 'if' statement BEFORE I
send the page to the browser?

P. S. - I am using the Google Groups editor and it puts my replies at
the top of the page. I can put my reply at the bottom of the page if
this helps...
Jan 29 '07 #6


On Jan 29, 9:58 am, "Schmidty" <schmi...@baronholding.comwrote:
On Jan 28, 5:55 am, Jerry Stuckle <jstuck...@attglobal.netwrote:


Schmidtywrote:
On Jan 26, 7:06 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>>Schmidtywrote:
>>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 - 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
(top posting fixed)
Schmidty,
You need to get over the thought of "reloading the variable...". The
server receives information from the browser and sends html back to the
browser. That's all. There is no "reload $_SERVER['PHP_SELF']" because
it server does not reload anything.
When a request for a page comes in, the web server loads the appropriate
page code. If the page is straight HTML, the code is sent to the
client. If the page includes script code such as PHP, the web server
loads the appropriate interpreter and calls it to execute the code.
The code is executed as it appears in the page. Output from the code is
sent to the webserver. When the page execution is complete, the output
is sent to the client and all resources used by that page are released.
Every page request is handled independently. $_SERVER['PHP_SELF'] is
just a string which refers to this page. You could have 'xyz.php'
instead. It would have the same effect.
In your example, the entire page is executed and sent to the browser.
the script then terminates. When the user presses the 'SUBMIT' button,
the form is submitted back to the the server. Since it is the same
page, the code is executed a second time.
P.S. Please don't top post.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================Jerry,

Thanks for your help on this. I am still learning the client/server
concepts with PHP as well as OOP so bare with me...

I understand what you have said and it makes sense. How would I update
the page with new information that is sent back from the database via
the server after clicking a 'submit' button? From what you are telling
me then, when the 'submit' button is pressed the script is re-
executed. In a function would I set the 'action' to a new page or use
the $_SERVER['PHP_SELF'] variable? Do I put an 'if' statement BEFORE I
send the page to the browser?

P. S. - I am using the Google Groups editor and it puts my replies at
the top of the page. I can put my reply at the bottom of the page if
this helps...
Jerry I think I figured it out!!!

I put two 'if' statements to check the form and then displayed the
contents what was queried from the browser!
Here is what I did;

Example ===============================================

if (isset($_POST['approved']) and isset($_POST['approve'])){
$passapproval=$_POST['approve'];
if ($passapproval){
foreach ($passapproval as $userid){ $nu->approveApps($userid);}
} // end if
} // end if
$nu->checkApps();

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

This works great and it makes sense with your explanation of the pages
being 'stateless'. Thanks for your help and hope to get more help from
you in the future. :)

Schmidty

Jan 29 '07 #7
Schmidty wrote:
>
On Jan 29, 9:58 am, "Schmidty" <schmi...@baronholding.comwrote:
>>==================Jerry,
Thanks for your help on this. I am still learning the client/server
concepts with PHP as well as OOP so bare with me...

I understand what you have said and it makes sense. How would I update
the page with new information that is sent back from the database via
the server after clicking a 'submit' button? From what you are telling
me then, when the 'submit' button is pressed the script is re-
executed. In a function would I set the 'action' to a new page or use
the $_SERVER['PHP_SELF'] variable? Do I put an 'if' statement BEFORE I
send the page to the browser?

P. S. - I am using the Google Groups editor and it puts my replies at
the top of the page. I can put my reply at the bottom of the page if
this helps...

Jerry I think I figured it out!!!

I put two 'if' statements to check the form and then displayed the
contents what was queried from the browser!
Here is what I did;

Example ===============================================

if (isset($_POST['approved']) and isset($_POST['approve'])){
$passapproval=$_POST['approve'];
if ($passapproval){
foreach ($passapproval as $userid){ $nu->approveApps($userid);}
} // end if
} // end if
$nu->checkApps();

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

This works great and it makes sense with your explanation of the pages
being 'stateless'. Thanks for your help and hope to get more help from
you in the future. :)

Schmidty
Hi, Schmidty.

Sorry for the delay in responding, but I had a hard disk crash and it
took me several days to get it back up and running again. But thank
$deity for backups! :-)

Yep, basically before you write your page, you have your PHP code check
the $_POST (or $_GET) array to see if data has been sent. If so,
process the data and then display the page. Otherwise, just display a
blank page.

You could also have the data sent do a different page which processes it
and redirects back to the original page (see the 'header' function).
But I find that usually makes things more complicated and harder to manage.

Glad you got it. And again, sorry to take so long to respond.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 2 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: nao | last post by:
Hi all! I am aware that this question might involve Javascript and MySQL. So far I haven´t found a suitable solution in JavaScript ng´s - maybe becauese php-programmers are more likely to come...
7
by: Jo | last post by:
Hi, I have a small (hopefully!) problem. I have two buttons on my web page and when button A is clicked, the code behind takes about 3 seconds to execute. While it's executing though, I don't want...
4
by: Don | last post by:
Given a page with a "header" and "main" frame, is there some way from the "header" frame to initiate re-execution of the JavaScrip/HTML code in the "main" frame? I don't want to have to reload...
1
by: brianj7675 | last post by:
Basically i'm trying to write a previous next link in order to go to the next page in my database(similar to google's with numbers in the middle for pages the user wants to jump to. My only...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
1
by: Björn Langhof | last post by:
Hello. I'd like to overwrite a native function. It's the reload()-function of the document.location-object. My idea: document.location.reload = function(){alert('foo')}; So if the function...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
5
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi, I used the following code to refresh the parent page, and it works very well (Thanks to Peter Bromberg "). Response.Write("<script language='javascript' type='text/javascript'{...
7
by: Gregor Kofler | last post by:
What is the best practice for removing anonymous functions? Something like (function() { doSomething(); arguments.callee = null; })(); seems to work (at least it triggers no errors or...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.