普通网友 2019-03-27 05:45
浏览 44

将图像上载到数据库时出现未定义的索引错误

I have a problem when uploading image into database using mysql.

When I click button for upload the image, the error comes out like this:

"Undefined index image in C:\xampp\htdocs\fyp\kemaskinipemandu.php" at line 29 and 30.

I've tried other solution from StackOverflow but it didn't work out at all. So, here is my html and my php code.

if (isset($_POST['kemaskini'])){
    $email = $_SESSION['driverEmail'];
    $nama = $_POST['nama'];
    $password = $_POST['password'];
    $cpassword = $_POST['cpassword'];
    $kp = $_POST['kp'];
    $tel = $_POST['tel'];
    $alamat = $_POST['alamat'];
    $exdate = date('Y-m-d', strtotime($_POST['lesen'])); 
    $class = $_POST['jenislesen'];

        $image = $_FILES['image']['name'];//imageUpload
        move_uploaded_file($_FILES['image']['tmp_name'], "img/".$_FILES['image']['name']);

        if($password === $cpassword){
            $query = "UPDATE driver SET driverName='$nama', driverPassword='$password', cpassword='$cpassword', driverICNum='$kp', contNum='$tel', 
            address='$alamat', licenseExDate='$exdate', class='$class', image='$image' WHERE driverID='$driverID';";
            $result = mysqli_query($conn, $query) or die(mysqli_error($conn));

        if($result)
          {
            ?>
            <script>
            alert('Kemas Kini Pemandu Berjaya. ');
            window.location.href="kemaskinipemandu.php";
            </script>
            <?php
          }
        }else {
        ?>
            <script>
            alert('Kata laluan tidak sama. ');
            window.location.href="kemaskinipemandu.php";
            </script>
        <?php
        }
}

and the line that have error are :

$image = $_FILES['image']['name'];//imageUpload move_uploaded_file($_FILES['image']['tmp_name'], "img/".$_FILES['image']['name']);

Select image to upload:

<form action="kemaskinipemandu.php" method = "POST" enctype="multipart/form-data">
    <center>
        <?php
        $email = $_SESSION['driverEmail'];
            $query=" SELECT * from driver where driverID='$driverID'";
            $result = mysqli_query($conn, $query) or die(mysqli_error($conn));
            $count = mysqli_num_rows($result);
            if (isset($count) and ($count > 0)) {
                    while($row = mysqli_fetch_assoc($result)){
                        $name = $row['driverName'];
                        $password = $row['driverPassword'];
                        $cpassword = $row['cpassword'];
                        $ic = $row['driverICNum'];
                        $contNum = $row['contNum'];
                        $address = $row['address'];
                        $exdate = $row['licenseExDate'];
                        $class = $row['class'];
                        $image = $row['image'];

        ?>
          <div class="col-md-6">
          <div class="form-group">
            <img src="<?php echo $image ?>" height="200" width="200"/><br><br>
            <div class="form-inline">
            Select image to upload:
            <input type="file" name="image" id="image" style="margin-left:2%"><br><br>
            </div>
            <label for="nama">Nama :</label>
            <input type="nama" class="form-control" name="nama" value="<?php echo $name ?>" ><br>
            <label for="email">Email :</label>
            <input type="email" class="form-control" name="email" value="<?php echo $email ?>" ><br>
            <label for="password">Kata Laluan :</label>
            <input type="password" class="form-control" name="password" value="<?php echo $password ?>" ><br>
            <label for="password">Pengesahan Kata Laluan :</label>
            <input type="password" class="form-control" name="cpassword" value="<?php echo $cpassword ?>" ><br>
            <label for="kp">No. Kad Pengenalan :</label>
            <input type="kp" class="form-control" name="kp" value="<?php echo $ic ?>" ><br>
            <label for="tel">No. Tel :</label>
            <input type="tel" class="form-control" name="tel" value="<?php echo $contNum ?>" ><br>
            <label for="alamat">Alamat :</label>
            <textarea type="alamat" class="form-control" name="alamat" rows="6"><?php echo $address ?></textarea><br>
            <label for="lesen">Tamat Tempoh Lesen Memandu :</label>
            <input type="date" class="form-control" name="lesen" value="<?php echo $exdate ?>" ><br>
            <label for="jenislesen">Lesen/Kelas:</label>
            <input type="text" class="form-control" name="jenislesen" value="<?php echo $class ?>" >
           </div>
           </div>
           <?php  } }?>
          <input type="submit" class="btn btn-primary" name="kemaskini" value="Kemas Kini"></br>
    </center>
    </form>

I hope someone can help me. Thank you.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大