I have error i have web site where want to users register this is code from index.php :

<?php
 include ('include/header.php');
 if (isset($_GET['id'])){
    switch ($_GET['id'])
    {
        case "wallpaper":
            include ("include/wallpaper.php");

            break;
            case "ringtones":
            include ("include/ringtones.php");

            break;
            case "themes":
            include ("include/themes.php");

            break;
            case "apps":
            include ("include/apps.php");

            break;
            case "aboutus":
            include ("include/aboutus.php");

            break;

            case "fannystuff":
            include ("include/fannystuff.php");

            break;
            case "register":
            include ("include/register.php");

            break;

            case "users":
            include ("include/users.php");

            break;
            }
 } else {
    include ('include/content.php');
 include ('include/sidebar.php');
 }
 include ('include/footer.php'); 

?>

But in register.php i have this error Notice: Undefined index: username in C:\wamp\www\Androidiks\include\register.php on line 3,4,5

This is code in register.php:

<?php
$submit = $_POST['submit'];
$username = $_POST['username'];
$password = $_POST['pasword'];
$repeatpassword = $_POST['repeatpassword'];
$email = $_POST['email'];

if($submit)
{

echo "$username/$password/$repeatpassword/$email";  

}

?>
<div id="registration">
 <h2>Create an Account</h2>

 <form id="RegisterUserForm" action="register.php" method='POST'>
    <fieldset>
         <p>
            <label for="name">Username</label>
            <input id="name" name="username" type="text" class="text" value="" />
         </p>
        <p>
            <label for="password">Password</label>
            <input id="password" name="password" class="text" type="password" />
         </p>
        <p>
            <label for="password">Repeat password</label>
            <input id="password" name="repeatpassword" class="text" type="password" />
         </p>

         <p>
            <label for="email">Email</label>
            <input id="email" name="email" type="email" class="text" value="" />
         </p>

         <p>
            <button id="registerNew" type="submit" name="submit">Register</button>
         </p>
    </fieldset>

 </form>
</div>
PLEASE HELP!

Instead of following code

<?php
$submit = $_POST['submit'];
$username = $_POST['username'];
$password = $_POST['pasword']; // <---wrong, s missing!!!
$repeatpassword = $_POST['repeatpassword'];
$email = $_POST['email'];
if($submit)
{
echo "$username/$password/$repeatpassword/$email";  
}
?>

check submitting like this, for example:

<?php
if(isset($_POST['submit']))
{
  $username = $_POST['username'];
  $password = $_POST['password'];
  $repeatpassword = $_POST['repeatpassword'];
  $email = $_POST['email'];
  echo "$username/$password/$repeatpassword/$email";  
}
?>
Thanks! But still have probllem with error,
When in form action="register.php" then i have problem that this page can't find on server and 
when action="index.php?id=register.php" erorr is :Notice: Undefined index: password in C:\wamp\www\Androidiks\include\register.php on line 13.
This is my index.php code: <?php
 include ('include/header.php');
 if (isset($_GET['id'])){
    switch ($_GET['id'])
    {
        case "wallpaper":
            include ("include/wallpaper.php");

            break;
            case "ringtones":
            include ("include/ringtones.php");

            break;
            case "themes":
            include ("include/themes.php");

            break;
            case "apps":
            include ("include/apps.php");

            break;
            case "aboutus":
            include ("include/aboutus.php");

            break;

            case "fannystuff":
            include ("include/fannystuff.php");

            break;
            case "register":
            include ("include/register.php");

            break;

            case "users":
            include ("include/users.php");

            break;


            }
 } else {
    include ('include/content.php');
 include ('include/sidebar.php');
 }
 include ('include/footer.php');




?>


and this how i make menu link in header:  <ul id="navigation">
          <li id="home"><a href="index.php"><span>Home</span></a></li> 
         <li id="wallpaper"><a href="index.php?id=wallpaper"><span>Wallpaper</span></a></li>
         <li id="ringtones"><a href="index.php?id=ringtones"><span>Ringtones</span></a></li>
         <li id="theme"><a href="index.php?id=theme"><span>Theme</span></a></li>
         <li id="apps"><a href="index.php?id=apps"><span>Apps</span></a></li>
         <li id="aboutus"><a href="index.php?id=aboutus"><span>About Us</span></a></li>
          <li id="fanny"><a href="index.php?id=fannystyff"><span>Fanny stuff</span></a></li>
        </ul>

Are you sure that your form and your register.php file are in the same directory. If you are having this error

When in form action="register.php" then i have problem that this page can't find on server

It simply means you are trying to post to a file that is not in the same directory with the form.

**when action="index.php?id=register.php" erorr is :Notice: Undefined index: password in C:\wamp\www\Androidiks\include\register.php
**

**index.php?id=register.php **

I have a problem with this statement. Please what are you trying to achieve with this.

Are you trying to perform a return redirection to register.php in the index.php file.
You need to get your algorithms write before making a form post.

Hi,

jUst to help you out on how to handle those switches gracefully. Just to let everybody know that there is nothing wrong with php switch function. However, in medium to large applications, it will become time consuming to write cases if hundreds of pages are involved. MVC framework design does offer the solutions and flexibilities to this conundrum, but that is not my objective here.. I just want to share a simple solution or rather an alternative way of doing switches..

ok... Let's do it.... First, I sincerely apologize for extra brackets on my sample usage ...I always get back to my old habit of parenthesizing every thing a little too much. You can develope this habit, if you hang around with Math and Physic geeks a lot ( excluding myself of course :)).

here we go.. the simplest and the shortest I can possibly think of..

function include_page($page){

$this_page = $page.'.php';
return(file_exists($this_page) ? true : false );

}

simple usage example ...

 if((isset($_GET['id'])) && (include_page($_GET['id']))){

    include_once(($_GET['id'].'.php'));

}
else{

   include ('include/content.php');
   include ('include/sidebar.php');

   ## if there is  no default page to include for false evaluation, then it should be set to false

    //false;
}

Simple function above can be modified to accept file extension ,dir , and even the GET[key] can be use as parameters if you want.

i do like this and i have error
<?php
include ('include/header.php');

  if((isset($_GET['id'])) && (include_page($_GET['id']))){
include_once(($_GET['id'].'.php'));
}
else{
include ('include/content.php');
include ('include/sidebar.php');


false;
}

include ('include/footer.php');

?>

i do like this and i have error 
<?php
 include ('include/header.php');

      if((isset($_GET['id'])) && (include_page($_GET['id']))){
    include_once(($_GET['id'].'.php'));
    }
    else{
    include ('include/content.php');
    include ('include/sidebar.php');


    false;
    }

   include ('include/footer.php');

?>


function include_page() in C:\wamp\www\Androidiks\index.php on line 4
Call Stack

function include_page() in C:\wamp\www\Androidiks\index.php on line 4
Call Stack

Do you have some advice how to do maybe in other way?

Hi,

Here is a sample script that can be easily modified to your needs.. Again, you need to test this several times and MUST provide the sufficient security measures for the form processor method get_formData(&$formVars)

First, create a new php file called Simple_Class.class.php and and paste codes below to this file.

<?php

## written by veedeoo 2013 => humbled and honored to be able to help Daniweb.com members
## there is no warranty nor guarantee given to this script
## Copyright announcement must remain intact.
## for further discussions must post question to daniweb forum


## we use interface for future expansion
/*
*@interface prepare database credentials
*
*/
interface db_credentials
{
   const DB_HOST = 'localhost';
   const DB_NAME = 'dbname';
   const DB_USER = 'db_user';
   const DB_PASS = '';
}

/*
*@simple_class class to do the heavy lifting
*@implements class uses the db_credentials
*/

class Simple_Class implements db_credentials{

    private $db;

    public function __construct(){

    }
## simple PDO interface just in case you need one
/*
*@db_connect method
*creates a PDO instance
*validates connection
*/
    private function db_connect(){
        try{
        $this->db = new PDO('mysql:host='.self::DB_HOST.';dbname='.self::DB_NAME.';charset=utf8', self::DB_USER, self::DB_PASS ,array(PDO::ATTR_PERSISTENT => true));
        $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
        return true;
        }
        catch(PDOException $err) {
                        return false;
                        die('OOPS Database Connection Problem detected: ' .$err->getMessage());
                    }
        }
/*
* if you need to expand the PDO method above, do so by creating a new pdo function below
*/

## A simple form processor
## Warning! this is not a sanitized variables suitable and not suitable for database..

    public function get_formData(&$formVars){
        $formVars = array();

        if(isset($_POST['submit'])&&(!empty($_POST['user_name']))|| (!empty($_POST['pass_word']))){
        $formVars['user'] = $_POST['user_name'];
        $formVars['pass']= $_POST['pass_word'];

        return $formVars;

        }

    }

## this is what you need to include pages..     
    public static function include_page($page){

        $this_page = $page.'.php';
        return(file_exists($this_page) ? true : false );

        }
}

save the page to your localhost...

Create another page called index.php copy and paste codes below

    require_once('Simple_Class.class.php');
    ## we require the class to call our static method to include page and to process our form, but we never instantiated it here.

    echo '<a href="?page=registration">Register</a> | <a href="?page=register">something</a> | <a href="?page=another">Other Page</a><br/>';
    if((isset($_GET['page'])) && (Simple_Class::include_page($_GET['page']))){

    $page = ($_GET['page']);
    include_once($page.'.php');

    }
    else{
    ## if the page to included above does not exist, the content.php will be included.
    include_once('content.php');

    }

    echo '<br/>';
    include_once('footer.php');

In the above codes, You must set this up depending on the pages you are trying to make..

echo '<a href="?page=registration">Register</a> | <a href="?page=register">something</a> | <a href="?page=another">Other Page</a><br/>';

create another php file called registration.php and paste codes below. I hate embedding PHP codes in the middle of html codes, so I have to define my form codes as PHP variables.

Filename: registration.php

<?php

## we define our ugly form.. it is all up to you to change it to your own.
$form = '<p>
<form action="" method="post">
<label for="username" >Username</label>
<input type="text" id="user_name" name="user_name"/>
<br/>
<label for="pass_word">Password</label>
<input type="password" id="password" name="pass_word" />
<br/>
<input type="submit" name="submit" value="submit"/>
</form>
</p>';

$object = new Simple_Class();

## I really hate the redundancy of my code implementations below, but I am typing
## these codes without giving it a 100% consideration about other things.

if(isset($_POST['submit']) && ($object->get_formData($formVars))){
$formVars = array();
$data = $object->get_formData($formVars);

echo '<h2>Submitted Form Data Summary</h2>';
echo '<hr/>';
echo 'Username: '.$formVars['user'];
echo '<br/>';
echo 'Password: '. $formVars['pass'];
echo '<hr/><br/>';


}
else
{
 echo $form;
}
?>

create your content.php and footer.php

If you noticed on the simple_class.class.php, I added a PDO connector... that is for you to experiment... you just need to provide the database credentials on the interface part of the script.

Things you need to add
1. Sanitization function or method
2. Login function with database validation

This should be really easy for you to implement,because I made as simple as it can be by using reference PHP function..

Larry Singleton will really hate me by getting away without the use or foreach loop :) :).. It is all about strategy Larry lol .....

@veedeo let us consider the person who seeks for help is a begginer for now.
@gogs85

if u cannot distinguish the file's current location I suggest you do this,
first--> debugging in INSPECT ELEMENT, then the look for the link or the button's link address if it is present
second--> use $_SERVER['PHP_SELF'] at the form tag's action attribute ( though this will cause more Security hole)

My 3 projects are completed in PHP but i want to Host in Google. i check it Xamp server. it will run correctly. so plz give me Hosting sites where i can buy a new domain or get a C-panel.

@Geffory there are lots of it

@masterjiraya.. plz send me these sites.

Thanks i will try this,thanks guys!

My all page is in folder include only index.php is not.
And when i use this on index.php code :     require_once('Simple_Class.class.php');
    ## we require the class to call our static method to include page and to process our form, but we never instantiated it here.
    echo '<a href="?page=registration">Register</a> | <a href="?page=register">something</a> | <a href="?page=another">Other Page</a><br/>';
    if((isset($_GET['page'])) && (Simple_Class::include_page($_GET['page']))){
    $page = ($_GET['page']);
    include_once($page.'.php');
    }
    else{
    ## if the page to included above does not exist, the content.php will be included.
    include_once('include/content.php');
    }
    echo '<br/>';
    include_once('include/footer.php');


 Don't show pages only show text from content without css style.

sorry i find my mistake

Show me content.php for all pages, how to change this, like i say my pages is in include folder how to change index.php code to work?

please help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.