0

Html file :

<form action="cregister.php" method="post" enctype="multipart/form-data" class="form-horizontal" id="wizForm">
        <input type="file" name="image" id="image" value="uploads/default.png" />
        <button type="button" id="simple-post" class="btn btn-success submitBtn">Submit</button>
</form>

action file :

$filename = $_FILES['image']['name'];
$path = "uploads";
move_uploaded_file($_FILES['image']['tmp_name'], $path."/".$filename);
$photo = $path."/".$filename;


$insert = "INSERT INTO user (photo)VALUES ('$photo')";
$sth = $db->query($insert);

Getting error

Notice: Undefined index: image

Jenz
  • 8,280
  • 7
  • 44
  • 77
Arvind
  • 25
  • 6

2 Answers2

2

The file dose not take value this way, value="uploads/default.png"

<input type="file" name="image" id="image" value="uploads/default.png" />

You will need to select file and submit form

print_r($_FILES) in action file.

Girish
  • 11,907
  • 3
  • 34
  • 51
0

Try This

HTML

<html>
  <form action="cregister.php" method="post" enctype="multipart/form-data" class="form-horizontal" id="wizForm">
        <input type="file" name="image" id="image" value="uploads/default.png" />
        <input type="submit" id="simple-post" class="btn btn-success submitBtn" value="Submit"/>
</form>  
</html>

PHP

<?php
    if(!empty($_FILES)){
        print_r($_FILES);
        $filename = $_FILES['image']['name'];
        $path = "uploads";
        move_uploaded_file($_FILES['image']['tmp_name'], $path."/".$filename);
        $photo = $path."/".$filename;
    }
?>
Mad Angle
  • 2,347
  • 1
  • 15
  • 33