-3

After click on submit this code is not sending data to database. can you help. also tried POST method.

these are my table name: in database.

id (AI),
image, 
name,
 dob, 
fathername, 
fatheroccupation, 
college, 
jscgpa, 
sscgpa, 
sscmaingpa, 
address, 
contact, 
email, 
homecontacts

I have tried different methods but none of them are working. Or can you please suggest me some GUI form builder for windows which i can use to create form that can send data to database? my codes are given below. I am currently learning php so new to this field.

<?php
$conn = mysqli_connect ('localhost','root','','admission');
?>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Admission Form</title>
<script type="text/javascript">
//auto expand textarea
function adjust_textarea(h) {
    h.style.height = "45px";
    h.style.height = (h.scrollHeight)+"px";
}
</script>
<link href="style.css" rel="stylesheet" type="text/css">

</head>



<body>

<div class="form-style-3">
<form action="" method="GET" enctype="multipart/form-data">
   <img border="0" alt="HOME-Mathreck" src="logo.png" width="50%" height="50%" class="logo"><br><br>
<fieldset><legend><b> Photo</b></legend>
    <label for="image"><span>Upload Your Photo: <span class="required">*</span></span><input type="file" class="input-field" name="image" id="image" /></label>
</fieldset>
<fieldset><legend><b>Personal Information</b></legend>
    <label for="name"><span>Name: <span class="required">*</span></span><input type="text" class="input-field" name="name" value="" /></label>

    <label for="dob"><span>Date of Birth: <span class="required">*</span></span><input type="date" class="input-field" name="dob" value="" /></label>

    <label for="fathername"><span>Father Name: <span class="required">*</span></span><input type="text" class="input-field" name="fathername" value="" /></label>

    <label for="fatheroccupation"><span>Father Occupation:: <span class="required">*</span></span><input type="text" class="input-field" name="fatheroccupation" value="" /></label>

    <label for="college"><span>College Name: <span class="required">*</span></span><input type="text" class="input-field" name="college" value="" /></label>
</fieldset>


<fieldset><legend><b>Education Information</b></legend>
    <label for="jscgpa"><span>JSC GPA: <span class="required">*</span></span><input type="text" class="input-field" name="jscgpa" value="" /></label>

    <label for="sscgpa"><span>SSC GPA: <span class="required">*</span></span><input type="text" class="input-field" name="sscgpa" value="" /></label>

    <label for="sscmaingpa"><span>SSC GPA (without 4th): <span class="required">*</span></span><input type="text" class="input-field" name="sscmaingpa" value="" /></label>

</fieldset>

 <fieldset><legend><b>Contacts Information</b></legend>

    <label for="address"><span>Address: <span class="required">*</span></span><textarea name="address" class="textarea-field"></textarea></label>
     <label for="contact"><span>Contact Number: <span class="required">*</span></span><input type="text" class="input-field" name="contact" value="" /></label>

    <label for="email"><span>Email: <span class="required">*</span></span><input type="email" class="input-field" name="email" value="" /></label>

    <label for="homecontacts"><span>Guardian Contact Number: <span class="required">*</span></span><input type="text" class="input-field" name="homecontacts" value="" /></label>
</fieldset>


<fieldset><legend><b> Confirm</b></legend>
    <h3><span>&nbsp;</span>Click to Submit</h3>
    <label><input type="submit" name="submit" value="SUBMIT" /></label>
</fieldset>
</form>
</div>
</body>
</html>
<?php

    $image = addslashes(file_get_contents($_FILES["image"]["tmp_name"]));
    $name = $_GET['name'];
    $dob = $_GET['dob'];
    $fathername = $_GET['fathername'];
    $fatheroccupation = $_GET['fatheroccupation'];
    $college = $_GET['college'];
    $jscgpa = $_GET['jscgpa'];
    $sscgpa = $_GET['sscgpa'];
    $sscmaingpa = $_GET['sscmaingpa'];
    $address = $_GET['address'];
    $contact = $_GET['contact'];
    $email = $_GET['email'];
    $homecontacts = $_GET['homecontacts'];

    $query = "INSERT INTO addata VALUES (?,$image, $name, $dob, $fathername, $fatheroccupation, $college, $jscgpa, $sscgpa, $sscmaingpa, $address, $contact, $email, $homecontacts)";
    $data = mysqli_query($conn,$query);
    if($data)
    {
        echo "Form Sucessfully Submited Contact Office Now";
    }
    else
    {
        echo "Error Submitting";
    }

?>

Thanks for your help.

Michael Nelles
  • 5,426
  • 8
  • 41
  • 57
  • 1
    [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)*** Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard Mar 25 '20 at 13:24

1 Answers1

-1

The following issue is occurring as you're probably trying to store the image instead of the path of the image. There are two approaches to the solution, see what suits your requirements best and go with it Approach 1: Ask for the user to give the URL of the desired image instead of asking to upload it via the form.

<input type="text" placeholder="Enter Image Url.." name="[Enter desired name]" />

and you can store it in a VARCHAR or a TEXTFIELD datatype in the database.

Approach 2: You can get image upload and store it on your server and then store the path to the database.

https://www.w3schools.com/php/php_file_upload.asp You can use this as a reference or alter according to the need and later store it's location to the server.

Michael Nelles
  • 5,426
  • 8
  • 41
  • 57
TG Himanshu
  • 78
  • 1
  • 9