PHP retrieving data from database.

Codes here !

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 10
Joined: Wed May 30, 2012 12:20 am

Fri Sep 28, 2012 11:34 pm

I am looking at an example database tutorial I found about how a simple C.R.U.D system works with PHP/MYSQL database. I have gotten it to work! However I am getting a little lost in the php manual on about the super global variable $_SERVER['PHP_SELF']. It states "is an array containing information such as headers, paths, and script locations."

So does that mean that whatever data that has just been inputted will be in $_SERVER['PHP_SELF']... in array form?

How do you retrieve data from previous queries that happened before submitted data from $_SERVER['PHP_SELF']? Maybe an SQL stament using a mysql_result($result) command?

Maybe I am making this more confusing than it should be.

Thanks in advance

Todd :)

New php-forum User
New php-forum User
Posts: 13
Joined: Thu Sep 27, 2012 10:55 am

Tue Oct 02, 2012 5:52 pm

$_SERVER['PHP_SELF'] simply refers to the current page with all its header, links, etc.. If you had a form and wanted to reload the page, you would process the field data before you generate any HTML. You could use this approach when you want to maintain the users input, maybe for a required fields check or some other pre submission routine. $_SERVER['PHP_SELF'] could be used like this:

At the top of your page, check for the super global $_POST array:

Code: Select all

if (!empty($_POST)){
  foreach($_POST as $key=>$value){
      ${$key} = $value;
     //instantiates $users = $_POST['users']
Then later in your HTML form:

Code: Select all

 <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="users" size="24" value="<?php echo $users;?>">

Post Reply