-1

i am trying to submit a query to my SQL server with a student ID as the tag and also the file names uploaded.

php part:

    if(isset($_POST['submit']))
    {
    $card=$_POST['card'];
    $SQL = "INSERT INTO cny2018 (cardnumber, timestamp, photo1) VALUES ('$card', '4-6 Days', '£75.00')";

     $result = mysql_query($SQL);

html part

<div class="form-group row">
<label for="example-search-input" class="col-2 col-form-label">ID:</label>
<div class="col-10">
<form>
    <input type="text" name="card"/>
</form>
    </div></div>
 <br><br>
Upload Photos (a maximum of 6 photos)<br>
<input id="file-input" type="file" multiple>
<div id="preview"></div>        
<br><br><br>
<form method="post">
<input class="btn btn-primary" type="submit" name="submit" value="Submit">
</form>
  • 1
    what is your question ? – sourabh1024 Aug 13 '17 at 15:15
  • Don't use `mysql_*` functions, they are deprecated as of PHP 5.5 and are removed altogether in PHP 7.0. Use [`mysqli`](http://php.net/manual/en/book.mysqli.php) or [`pdo`](http://php.net/manual/en/book.pdo.php) instead. [**And this is why you shouldn't use `mysql_*` functions**](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). – Rajdeep Paul Aug 13 '17 at 15:17

1 Answers1

0

In HTML part, you didn't mention action attribute for the form, also you are uploading images but you didn't write enctype="multipart/form-data" and you didn't provide name attribute for the file-upload element. In PHP part, if you want to store the name of the uploaded image, you need to store the name to a variable. Then you need to add the variable to the SQL query. For example,

 $card=$_POST['card'];
 $orig_filename=$_FILES['your_image_name']['name'];
 $SQL = "INSERT INTO cny2018 (cardnumber, timestamp, photo1) VALUES ('$card', '4-6 Days', '$orig_filename')";
 $result = mysql_query($SQL);

And lastly, I would like to advice that you should not use mysql_query() function as it is deprecated, instead use mysqli_query or PDO.

http://php.net/manual/en/book.mysqli.php

http://php.net/manual/en/book.pdo.php

Nilesh Sanyal
  • 836
  • 6
  • 10