www.webdeveloper.com
Results 1 to 5 of 5

Thread: Undefined Index

  1. #1
    Join Date
    Dec 2011
    Posts
    39

    Undefined Index

    Sir, I am using these codes

    PHP Code:
    // UPDATE
            
        
    if(isset($_POST['update']))
        {
        
    // Get values from form 
        
    $name=$_POST['name'];
        
    $moba=$_POST['moba'];
        
    $mobb=$_POST['mobb'];
        
    $ptcl=$_POST['ptcl'];
        
    $fax =$_POST['fax'];
        
    $email=$_POST['email'];
        
    $web =$_POST['web'];
        
    $add =$_POST['add'];
        
    $city =$_POST['city'];
        
    $country =$_POST['country'];
        
    $job =$_POST['job'];
        
    $office =$_POST['office'];
        
    $place =$_POST['place'];
        
    $phone =$_POST['phone'];
        
    $others =$_POST['others'];


        if (empty(
    $moba)){
                echo 
    "<script>alert('No username is selected')</script>";
            }else{
                
    $query "UPDATE contacts SET  name=$name mobb=$mobb ptcl=$ptcl fax=$fax email=$email web=$web address=$add city=$city country=$country job=$job office=$office place=$place phone=$phone others=$others where moba='".$_POST['$moba']."'";
                
    $result mysqli_query($con$query)or die (mysqli_error());
            
            
    //check update
                
    if(!$result)
                {
                echo (
    "<script>alert('Sorry! Something went wrong.')</script>");
                }else{
                echo (
    "<script>alert('Record updated successfully')</script>"); 
                }
            }
            } 

    but it says:
    Notice: Undefined index: $moba in C:\wamp\www\Phonebook\contacts.php on line 110

    and line 110 is
    PHP Code:
    $query "UPDATE contacts SET  name=$name mobb=$mobb ptcl=$ptcl fax=$fax email=$email web=$web address=$add city=$city country=$country job=$job office=$office place=$place phone=$phone others=$others where moba='".$_POST['$moba']."'"
    My database is as follows:

    http://i44.tinypic.com/jpzwok.jpg

    What I am doing wrong?
    Please help me

  2. #2
    Join Date
    Jul 2012
    Location
    Vancouver
    Posts
    61
    It means it can't find $_POST['$moba'].

    When using single quotes '' it will try and literally find $moba and not the variable $moba.

    Also, that query is pure sql injection waiting to happen.

  3. #3
    Join Date
    Dec 2011
    Posts
    39
    Quote Originally Posted by mistin.ca View Post
    It means it can't find $_POST['$moba'].

    When using single quotes '' it will try and literally find $moba and not the variable $moba.

    Also, that query is pure sql injection waiting to happen.
    I do not know what is sql injection?

  4. #4
    Join Date
    Nov 2013
    Posts
    33
    use isset or empty to make sure that variables have values.
    PHP Code:
    if(isset($_POST['update'])) 
        { 
        
    // Get values from form  
        
    $name= isset($_POST['name']) ? $_POST['name'] : 'Set something here or leave blank'
        
    $moba= empty($_POST['moba']) ? 'set something here or leave blank' $_POST['moba'] ; 
    and so on.

    Undefined index: - just means that php is trying to read a unset variable and it does not like that.

    As to the SQL injection, that is when somebody can run malicious query on your database due to no sanitation or security checks. read this

  5. #5
    Join Date
    May 2004
    Location
    chennai, tamil nadu, India
    Posts
    437
    Quote Originally Posted by tqmd1 View Post

    Notice: Undefined index: $moba in C:\wamp\www\Phonebook\contacts.php on line 110
    Quote Originally Posted by mistin.ca View Post

    When using single quotes '' it will try and literally find $moba and not the variable $moba.
    What mistin.ca means is, you must use $_POST[$moba] instead of $_POST['$moba']
    Chris, Senior Developer,
    www.Chrisranjana.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles