0

I'm creating a form in html which will run php file and upload image and text in database.My html is directing perfectly to php but the uploading process not working.Everytime the submit button pressed,the php file show not working.

My Html Code :

<form name="f1" method="post" action="php/Savent.php" 
 enctype="application/x-www-form-urlencoded">
    <fieldset>
        <legend name = "addev" align="right"><b>Detail</b></legend>
        <table width="100%">
            <tr align="center">
                <th>Choose Image : </th>
                <td><input type="file" name="image"/></td>
            </tr>
            <tr>
                <td colspan="2"><br/></td>
            </tr>
            <tr align="center">
                <th>Description : </th>
                <td><textarea name="desc" rows="6" cols="30" style="resize: 
                     none"></textarea></td>
            </tr>
            <tr>
                <td colspan="2"><br/></td>
            </tr>
            <tr align="center">
                <td colspan="2" align="center"><input name="submit" 
                  type="submit" value="Submit"/> <input type="reset" 
                  value="Reset"/></td>
            </tr>
            <tr>
                <td colspan="2"><br/></td>
            </tr>
        </table>

Php Code :

 <?php

  if(isset($_POST["submit"])){
    mysqli_connect("sql303.unaux.com","unaux_20153623","testin");
    mysqli_select_db("unaux_20153623_dummy");

    $imageName = mysqli_real_escape_string($_FILES["image"]["name"]);
    $imageData = 
    mysqli_real_escape_string(file_get_contents($_FILES["image"]
    ["tmp_name"]));
    $imageType = mysqli_real_escape_string($_FILES["image"]["type"]);
    $desc = mysqli_real_escape_string($_POST["desc"]);

    if (substr($imageType,0,5) == "image"){
        echo "Working";
    mysqli_query("INSERT INTO 'events' 
    VALUES('','$imageName','$imageData','$desc')");
    echo "Saved Succesfully";
    }
    else{
    echo "Not Working";
    }
   }

   ?>
damn er
  • 31
  • 6
  • 1
    You're using the wrong enctype. See https://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean – Tieson T. May 27 '17 at 18:55
  • Also you need to pass your connection variable when executing the query. – Rotimi May 27 '17 at 18:58
  • Also in your insert statement, you need to use backticks and not single quotes around your table name. Make sure the events table has got only 4 columns – Rotimi May 27 '17 at 19:01

1 Answers1

0

add this enctype="multipart/form-data" in form element you are using wrong enctype

user3337667
  • 161
  • 1
  • 10