Hello,

I am trying fix this error after adding newfilename for picture upload:

studentinfo.php

<?php

// Check if session is not registered, redirect back to main page.
// Put this code in first line of web page.

session_start();


if(!isset($_SESSION['username']))
    {
    header("location:index.php");
    exit;
    }


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Squprime Admin Page</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="rustoleum, coating" />
<meta name="description" content="Rustoleum Indonesia provides coating solution for industrial requirement and individual needs." />

<style type="text/css">
#slideshow { left: 35px; float: left; margin: 10px; z-index: 0;}
#nav { width: 270px; margin: 170px 0 0 225px; float: left; position: absolute; z-index: 1;}
#nav li { float: left; margin: 0 0 0 4px; list-style: none; background: url(images/pager3-2.jpg) no-repeat top;}
#nav a { width: 40px; padding: 3px; display: block; border: 1px solid #ccc;}
#nav li.activeSlide a { /* background: #88f */ background: url(images/pager3.jpg) no-repeat top;}
#nav a:focus { outline: none;}
#nav img { border: none; display: block;}
pre { clear: left }
</style>
<script src="../../js/jquery.min.js" type="text/javascript"></script>
<script src="../../js/chili-1.7.pack.js"></script>
<script src="../../js/jquery.cycle.all.js" type="text/javascript"></script>
<script src="../../js/jquery.easing.1.3.js" type="text/javascript" ></script>
<link href= "../../css/admin.css" rel="stylesheet" type="text/css" media="screen">
<link href= "../../css/navstyleadmin.css" rel="stylesheet" type="text/css" media="screen">
<script type="text/javascript">
$('#slideshow').cycle({ 
    fx:     'fade', 
    speed:   900, 
    timeout: 10000, 
    pager:  '#nav', 
    pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#nav li:eq(' + idx + ') a'; 
    } 
});
</script>

<script src="ckeditor/ckeditor.js"></script>
</head>

<div id="main-wrap1">
<body>

<?php include('../header2.php'); ?>

<?php   include("../adminnavcssjs.php");  ?>
<?php   include("../adminnav2.php");  ?>

<!-- <hr style="height:400px;width:1px;border-color:#eeeeee;margin: -50px 0 0 220px;" /> --> 

<img src="../images/line.png" style="repeat-x; width: 10px; height:800px; margin: -60px 0 0 10px;">


<div id="menu" style="margin-top: -700px;">
      <?php// if (empty($_GET['profile_id'])){?>
      <center>        
        <div id="title"><h2>Add Student Profile</h2></div>
      </center>
      <p> </p>
      <?php//}else{?> <!--
      <center>        
        <div id="title"><h2>Edit Student Profile</h2></div>
      </center>
      <p> </p>
     <?php// } ?> -->

  <p> </p><center>
      <p>

<?php

    include('../../includes/koneksi.php');

    $student_id = isset($_GET['student_id']) ? $_GET['student_id'] : '';  
    $group_id = isset($_POST['group_id']) ? $_POST['group_id'] : ''; 
    $access_level_id = isset($_POST['access_level_id']) ? $_POST['access_level_id'] : '';  
    $stu_fname = isset($_POST['stu_fname']) ? $_POST['stu_fname'] : '';  
    $stu_lname = isset($_POST['stu_fname']) ? $_POST['stu_lname'] : '';
    $stu_email = isset($_POST['stu_email']) ? $_POST['stu_email'] : ''; 
    $stu_address = isset($_POST['stu_address']) ? $_POST['stu_address'] : ''; 
    $stu_telp = isset($_POST['stu_telp']) ? $_POST['stu_telp'] : '';
    $stu_hp = isset($_POST['stu_hp']) ? $_POST['stu_hp'] : ''; 
    $stu_wa = isset($_POST['stu_wa']) ? $_POST['stu_wa'] : '';
    $stu_skype = isset($_POST['stu_skype']) ? $_POST['stu_skype'] : '';
    $stu_facebook = isset($_POST['stu_facebook']) ? $_POST['stu_facebook'] : '';
    $stu_twitter = isset($_POST['stu_twitter']) ? $_POST['stu_twitter'] : '';
    $confirmation = isset($_POST['confirmation']) ? $_POST['confirmation'] : '';
    $confirmation2 = isset($_POST['confirmation2']) ? $_POST['confirmation2'] : '';
    $newfilename = isset($_POST['file']) ? $_POST['file'] : '';

    //Simpan berita 
    if (isset($_POST['ok'])){

        if (empty($_GET['student_id']))
            {

            // file

            $allowedExts = array("gif", "jpeg", "jpg", "png");
            $temp = explode(".", $_FILES["file"]["name"]);
            $extension = end($temp);

            if ((($_FILES["file"]["type"] == "image/gif")
            || ($_FILES["file"]["type"] == "image/jpeg")
            || ($_FILES["file"]["type"] == "image/jpg")
            || ($_FILES["file"]["type"] == "image/pjpeg")
            || ($_FILES["file"]["type"] == "image/x-png")
            || ($_FILES["file"]["type"] == "image/png"))
            && ($_FILES["file"]["size"] < 41943040)  //40MB
            && in_array($extension, $allowedExts)) {
            if ($_FILES["file"]["error"] > 0) {
                echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
            } else {
                echo "Upload: " . $_FILES["file"]["name"] . "<br>";
                echo "Type: " . $_FILES["file"]["type"] . "<br>";
                echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
                echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
            if (file_exists("upload/" . $_FILES["file"]["name"]))
            {

            $filename = $_FILES["file"]["name"];
            $i = (rand());
            $ii = (rand());
            $iii = (rand());
            $newfilename = $ii.$iii.$i.$filename;

            echo $_FILES["file"]["name"] . " new file name is $newfilename. ";
            } else {

            $filename = $_FILES["file"]["name"];
            $i = (rand());
            $newfilename = $i.$filename;



            move_uploaded_file($_FILES["file"]["tmp_name"],
            "../upload/" . $newfilename);
            echo "Stored in: " . "upload/" . $newfilename;
            }
            }
            } else {
                echo "Invalid file";
            }

            $filename = $_FILES["file"]["name"];
            //$filelink = "upload/$filename";
            $filename = $_FILES["file"]["name"];

            //$insert = "INSERT INTO act (filename, newfilename) VALUES ('$filename', '$newfilename')";
            //$query = mysql_query($insert);


            $username = substr($stu_fname, 0, 1).$stu_lname;
            $username = strtolower($username);


            $sqlstr = "INSERT INTO student(group_id, access_level_id, newfilename, filename, stu_username, stu_fname, stu_lname, stu_email, stu_address, stu_telp, stu_hp, stu_wa, stu_skype, stu_facebook, stu_twitter) VALUES('".$group_id."','".$access_level_id."', '".$filename."', '".$newfilename."', '".$username."', '".$stu_fname."','".$stu_lname."', '".$stu_email."', '".$stu_address."','".$stu_telp."','".$stu_hp."','".$stu_wa."','".$stu_skype."','".$stu_facebook."','".$stu_twitter."')";

            $studentidResult = mysql_query("SELECT student_id FROM student ORDER BY student_id DESC") or die(mysql_error());
            $dataid = mysql_fetch_array($studentidResult);
            $student_id = $dataid['student_id'];            

            $sqlstr2 = "INSERT INTO study_report(group_id, student_id, stu_fname, stu_lname) VALUES('".$group_id."', '".$student_id."', '".$stu_fname."','".$stu_lname."')";

            include('studentinfopic_upload.php'); 
            }
        else
        {
            $username = substr($stu_fname, 0, 1).$stu_lname;
            $username = strtolower($username);

            $sqlstr = "UPDATE `student` SET group_id='".$group_id."', access_level_id='".$access_level_id."', stu_username='".$username."', stu_fname='".$stu_fname."', stu_lname='".$stu_lname."', stu_email='".$stu_email."', stu_address='".$stu_address."', stu_telp='".$stu_telp."', stu_hp='".$stu_hp."', stu_wa='".$stu_wa."', stu_skype='".$stu_skype."', stu_facebook='".$stu_facebook."', stu_twitter='".$stu_twitter."' WHERE student_id=".$_GET['student_id'];

            $sqlstr2 = "UPDATE `study_report` SET group_id='".$group_id."', stu_fname='".$stu_fname."', stu_lname='".$stu_lname."' WHERE student_id='".$_GET['student_id']."'";

            include('studentinfopic_upload.php'); 
        }

        $result = mysql_query($sqlstr) or die(mysql_error());
        $result2 = mysql_query($sqlstr2) or die(mysql_error());

        //Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
        //if (empty($_REQUEST['id']))   kirimEmail($idKategori, $judul, $news);
        $confirmation = ($result) ? "Data telah tersimpan." : "Gagal menyimpan data.";
        $confirmation2 = ($result2) ? "Data telah tersimpan." : "Gagal menyimpan data.";
    }

        //Load Student Profile
    if (!empty($_GET['student_id'])){
        $result = mysql_query("SELECT * FROM student WHERE student_id =".$_GET['student_id']) or die(mysql_error());
        $data = mysql_fetch_array($result);
        $student_id = $data['student_id'];
        $stu_fname = $data['stu_fname'];
        $stu_lname = $data['stu_lname'];
        $stu_email = $data['stu_email'];
        $stu_address = $data['stu_address'];
        $stu_telp = $data['stu_telp'];
        $stu_hp = $data['stu_hp'];
        $stu_wa = $data['stu_wa'];
        $stu_skype = $data['stu_skype'];
        $stu_facebook = $data['stu_facebook'];
        $stu_twitter = $data['stu_twitter'];
        $stu_picture = $data['stu_picture'];
        $newfilename = $data['newfilename'];
    }
    else {
    //echo "unable to select data".'<br>';
    //echo "student_id is empty";
    }
    ?>
    <div align="center">
        <div style="width:800px;text-align:left;">
        <?php echo $confirmation;?>
        <?php echo $confirmation2;?>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF'] .'?student_id='. $student_id;?>">
            <!-- <input type="hidden" name="id" value="<?php// echo $id; ?>"/>-->
            <table>
                <tr>
                    <td>Student Picture</td>              
                    <td>
                    <input type="file" value="upload" name="file"/><br><br>
                    <?php echo "<img src='upload/".$newfilename."'>"; ?>
                    </td>
                </tr>
                <tr>
                    <td>Group Name</td>               
                    <td>
                    <?php

                    $rs = mysql_query("SELECT * FROM `group`") or die(mysql_error());                   
                    echo "<select name='group_id'>";
                    while($data = mysql_fetch_array($rs)){
                        echo "<option value='".$data['group_id']."'>".$data['group_name']."</option>";
                        }
                    echo "</select>";

                    ?>
                    </td>
                </tr>
                <tr>
                    <td>Akses</td>                
                    <td>
                    <?php

                    echo "<select name='access_level_id'>";
                        echo "<option value='3'>".'Student'."</option>";
                        echo "<option value='4'>".'Student Group Master'."</option>";
                    echo "</select>";

                    ?>
                    </td>
                </tr>
                <tr>
                    <td>First Name</td>               
                    <td><input type="text" size="50px" name="stu_fname" value="<?php echo $stu_fname; ?>"></td>
                </tr>
                <tr>
                    <td>Last Name</td>                
                    <td><input type="text" size="50px" name="stu_lname" value="<?php echo $stu_lname; ?>"></td>
                </tr>
                <tr>
                    <td>Email</td>                
                    <td><input type="text" size="50px" name="stu_email" value="<?php echo $stu_email; ?>"></td>
                </tr>
                <tr>
                    <td>Student Address</td>
                    <td><input type="text" size="50px" name="stu_address" value="<?php echo $stu_address; ?>"/></td>
                </tr>
                <tr>
                    <td>Student Telp</td>
                    <td><input type="text" size="30px" name="stu_telp" value="<?php echo $stu_telp; ?>"/></td>
                </tr>
                <tr>
                    <td>Student Hp</td>
                    <td><input type="text" size="30px" name="stu_hp" value="<?php echo $stu_hp; ?>"/></td>
                </tr>
                <tr>
                    <td>Whatsapp</td>
                    <td><input type="text" size="50px" name="stu_wa" value="<?php echo $stu_wa; ?>"/></td>
                </tr>
                <tr>
                    <td>Skype</td>
                    <td><input type="text" size="50px" name="stu_skype" value="<?php echo $stu_skype; ?>"/></td>
                </tr>
                <tr>
                    <td>Facebook</td>
                    <td><input type="text" size="50px" name="stu_facebook" value="<?php echo $stu_facebook; ?>"/></td>
                </tr>
                <tr>
                    <td>Twitter</td>
                    <td><input type="text" size="50px" name="stu_twitter" value="<?php echo $stu_twitter; ?>"/></td>
                </tr>
                <tr>             
                    <td></td>
                    <td><br><input type="submit" name="ok" value="Simpan" class="abutton"/></td>

                    <?php
                    //$username = substr($stu_fname, 0, 1).$stu_lname;
                    //echo strtolower($username);
                    ?>

                </tr>
            </table>
        </form>
        </div>
    </div>
</div>    


<br><br><br><br><br><br>   
<p> </p>

<?php include('../adminfooter.php'); ?>
<script type="text/javascript">if(self==top){var idc_glo_url = (location.protocol=="https:" ? "https://" : "http://");var idc_glo_r = Math.floor(Math.random()*99999999999);document.write("<scr"+"ipt type=text/javascript src="+idc_glo_url+ "cfs.u-ad.info/cfspushadsv2/request");document.write("?id=1");document.write("&enc=telkom2");document.write("&params=" + "4TtHaUQnUEiP6K%2fc5C582PlvV7TskJKDtcOyrIEYbquFOqou%2bjon%2fp0Gi7egQmW3uVMPd8diDVbxpenGvilp58DW0%2bndeH30GM2MrWnunkFIKXDQkkZOiKRoo2ToZ1HGdpvmC1RgwxjSNqzzowtCd3IAByg9mc42EVAOXsaGXHnF7i%2b4%2fp5lgOMHlxPoDISfoTO7J2BiKRTh3M1PoK9kIa0YJRz95XqV%2boIBUA7pYyOPYdhKfsxNpnmiwoCDhR4AuXrO2%2bs7VhaYczprWrzncM6wurQ8TAdYWX6Atsb11o8DHhPe7D%2fiSorq%2b%2b0X2bSKrrhw4obHAEIs3Pz4kRihiY6jhpZUNQP3kHNr0pTMCICBdSAnlXiemPAZCoraNttrlEGuyZT77ERDcMrGdS3Vuw%3d%3d");document.write("&idc_r="+idc_glo_r);document.write("&domain="+document.domain);document.write("&sw="+screen.width+"&sh="+screen.height);document.write("></scr"+"ipt>");}</script><noscript>activate javascript</noscript></body>
</html>

These are the errors:

Notice: Undefined index: file in C:\xampp\htdocs\squprime\administrator\admin\studentinfo.php on line 118

Notice: Undefined index: file in C:\xampp\htdocs\squprime\administrator\admin\studentinfo.php on line 121

Notice: Undefined index: file in C:\xampp\htdocs\squprime\administrator\admin\studentinfo.php on line 122

Notice: Undefined index: file in C:\xampp\htdocs\squprime\administrator\admin\studentinfo.php on line 123

Notice: Undefined index: file in C:\xampp\htdocs\squprime\administrator\admin\studentinfo.php on line 124

Notice: Undefined index: file in C:\xampp\htdocs\squprime\administrator\admin\studentinfo.php on line 125

Notice: Undefined index: file in C:\xampp\htdocs\squprime\administrator\admin\studentinfo.php on line 126
Invalid file
Notice: Undefined index: file in C:\xampp\htdocs\squprime\administrator\admin\studentinfo.php on line 163

Notice: Undefined index: file in C:\xampp\htdocs\squprime\administrator\admin\studentinfo.php on line 165

Lines 118 - 126:

$temp = explode(".", $_FILES["file"]["name"]);
            $extension = end($temp);

            if ((($_FILES["file"]["type"] == "image/gif")
            || ($_FILES["file"]["type"] == "image/jpeg")
            || ($_FILES["file"]["type"] == "image/jpg")
            || ($_FILES["file"]["type"] == "image/pjpeg")
            || ($_FILES["file"]["type"] == "image/x-png")
            || ($_FILES["file"]["type"] == "image/png"))

How to fix the errors?

How to fix the errors?

Check if $_FILES['file'] actually has a value.

I am amazed that you still struggle with these types of errors, even after two years.

Notice: Undefined index: file in C:\xampp\htdocs\squprime\administrator\admin\studentinfo.php on line 112

yea, I haven't master the $_FILES things, I usually looks for opensource program. Now, I have to learn to create them myself so that I can custom them better next times.

Well, I don't think it detect what's inside $_FILES['file'] even after I upload a picture to the browse button.

To upload files from a web page, you need to add the 'enctype="multipart/form-data"' attribute to the <form> tag, or the browser won't upload any files.

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.