Using post method in PHP to save data to database -


this question has answer here:

i'm checking whether or not text box has value or not before saving database. i'm creating movie website, validation working fine.

the problem saving, i'm uploading picture movie. picture being upload folder web site application directory, problem here i'm having error code while clicking on save

notice: undefined index: photoimg in c:\xampp\htdocs\star_crud\home.php on line 233

notice: undefined index: photoimg in c:\xampp\htdocs\star_crud\home.php on line 234

my code below :

if (isset($_post['create'])) {      // keep track post values     $cast = $_post['cast'];     $title = $_post['title'];     $comment =$_post['comment'];     $year = $_post['year'];     $tag = $_post['tags'];     $idbm = $_post['idbm'];     $cast = htmlspecialchars($cast);     $title = htmlspecialchars($title);     $comment = htmlspecialchars($comment);      // validate input     $valid = true;     if (empty($cast)) {         $casterror = 'please enter cast';         $valid = false;     }      if (empty($title)) {         $titleerror = 'please enter title';         $valid = false;     }       if (empty($comment)) {         $commenterror = 'please enter comment';         $valid = false;     }     if ($valid) {           $valid_formats = array("jpg", "png", "gif", "bmp");           $name = $_files['photoimg']['name'];         $size = $_files['photoimg']['size'];          if(strlen($name))             {                 list($txt, $ext) = explode(".", $name);                 if(in_array($ext,$valid_formats))                 {                 if($size<(1024*1024))                     {                         $actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext;                         $tmp = $_files['photoimg']['tmp_name'];                         if(move_uploaded_file($tmp, $path.$actual_image_name))                             {                              echo "hi";                             }                         else                             echo "failed";                     }                     else                     echo "image file size max 1 mb";                                         }                     else                     echo "invalid file format..";                }          else             echo "please select image..!";          exit;        }     }     else echo "error"; 

i have done check removing statement in if(valid) statement, , print string, work, think problem come statement.

<form class="form-horizontal" id="form1" action="home.php" method="post">                      <div class="control-group <?php echo !empty($titleerror)?'error':'';?>">                     <label class="control-label">title</label>                     <div class="controls">                         <input name="title" type="text"  placeholder="title" value="<?php echo !empty($title)?$title:'';?>">                         <?php if (!empty($titleerror)): ?>                             <span class="help-inline"><?php echo $titleerror;?></span>                         <?php endif; ?>                     </div>                   </div>                   <div class="control-group <?php echo !empty($emailerror)?'error':'';?>">                     <label class="control-label">year</label>                     <div class="controls">                        <?php                          $years = range (2011, 2021);                         echo '<select name="year">';                             foreach ($years $value) {                             echo "<option value=\"$value\"> $value</option>\n";                                 }                                 echo '</select>';                         ?>                     </div>                   </div>                     <div class="control-group <?php echo !empty($emailerror)?'error':'';?>">                     <label class="control-label">category</label>                     <div class="controls">                        <?php                           require 'db2.php';                          $q1 = mysqli_query($dbc,"select name category ");                            echo "<select name='category'>";                       while ($row = mysqli_fetch_array($q1)) {                          echo "<option value='" . $row['name'] . "'>" . $row['name'] . "</option>";                             }                            echo "</select>";                        ?>                     </div>                   </div>                   <div class="control-group <?php echo !empty($casterror)?'error':'';?>">                     <label class="control-label">cast</label>                     <div class="controls">                         <input name="cast" type="text"  placeholder="cast" value="<?php echo !empty($cast)?$cast:'';?>">                         <?php if (!empty($casterror)): ?>                             <span class="help-inline"><?php echo $casterror;?></span>                         <?php endif;?>                     </div>                   </div>                   <div class="ajaxform">                     <div class="control-group <?php echo !empty($imageerror)?'error':'';?>">                     <label class="control-label">image upload</label>                     <div class="controls">                       <input type="file" name="photoimg"  onchange="readurl(this);" id="photoimg" /><br/>                           <img id="blah"  src="#"  height="150" width="150"  alt="your image" />                        </div>                 </div>                    </div>                     <div class="control-group <?php echo !empty($tagserror)?'error':'';?>">                     <label class="control-label">tags</label>                     <div class="controls">                         <input name="tags" id="mysinglefield" type="hidden"  > <!-- disabled demonstration purposes -->                          <ul id="singlefieldtags"></ul><?php if (!empty($tagserror)): ?>                             <span class="help-inline"><?php echo $tagserror;?></span>                         <?php endif; ?>                     </div>                   </div>                     <div class="control-group <?php echo !empty($idmberror)?'error':'';?>">                     <label class="control-label">idbm</label>                     <div class="controls">                          <input name="idbm"  type="textarea"><?php if (!empty($idmberror)): ?>                             <span class="help-inline"><?php echo $idmberror;?></span>                         <?php endif;?>                      </div>                   </div>                     <div class="control-group <?php echo !empty($commenterror)?'error':'';?>">                     <label class="control-label">comment</label>                     <textarea name="comment" id="comment" rows="4" style="width:780px" cols="50">                     </textarea>                     <?php if (!empty($commenterror)): ?>                             <span class="help-inline"><?php echo $commenterror;?></span>                         <?php endif;?>                     <div class="controls">                       </div>                   </div>                   <div class="form-actions">                       <button type="submit" name="create" class="btn btn-success">create</button>                       <a class="btn" href="index.php">home</a>                     </div>                 </form> 

photoimg should name of input field:

<input type='file' name='photoimg' /> 

since isn't, offset of $_files array doesn't work, , php can't access of sub-keys (tmp_name, etc).


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -