0

I am new to web designing and i just got an assignment from my class to create a jQuery application. the application will require a user to submit a data that should be saved to a database! My friend told me that when i have created the php connection, i should save them bothe the HTML and PHP files in the database mysql folder, i use xampp as my mysql server.

Now the problem is once i click the submit button, the page loads but does not display anything and the data isnt uploaded to the database. How can i handle this to successfully upload my data to the database?

Here is my html file with the form

 <form action="con.php" method="POST" enctype="multipart/form-data">
                <div style="padding:20px 20px;">
                    <h2>Personal Details</h2>
                    <p>In this section, we would like you to provide your personal details.</p>
                    
                    <label for="name">Name:</label>
                    <input type="text"  name="fullname" placeholder="enter your fullname" data-theme="a" required/>
                    <label for="PhoneNumber">Phone Number:</label>
                    <input type="number"  name="phonenumber" placeholder="enter your phone number" data-theme="a" required/>

                    <label for="mail">E-Mail:</label>
                    <input type="text" name="email" value=""placeholder="enter your e-mail address" data-theme="a" required/>
                    
                    <div data-role="controlgroup" data-type="horizontal" data-mini="true" required/>
                        <h4>Gender</h4>
                        <input type="radio" name="gender" value="f" id="gender" required/>
                        <label for="gender">Female</label>
                        <input type="radio" name="gender" value="m" id="gender2" required/>
                        <label for="gender2">Male</label>
                    </div>
                    <h2>Description</h2>
                    <p>Provide in detail the description of the case you are reporting and to where it took place.</p>
                    <label for="location">Location</label>
                    <input type="text"  name="location" placeholder="enter where you are reporting from" data-theme="a" required/>
                        
                    <label for="title">Title:</label>
                    <input type="text" name = "title" id="title"  value=""placeholder="enter the title of the case you are reporting" data-theme="a" required/>
                    <label for="description">Description:</label>
                    <textarea cols="40" rows="8" name = "description" id = "textarea" value=""placeholder="describe the case you are reporting" required/></textarea>
                    <div data-role="fieldcontain">
                        <label for="picture">Upload a picture or a video file for evidence: </label>
                        <input type="file" name = "image" id="picture" id="picture" required/>

                    </div>
                    
                    <div data-role="fielcontain">
                        <label for="terms">Before you proceed, please read to Terms and Conditions applied. Click <a href="#page3">here</a> to read the terms and conditions</label>
                        <select name="terms" id="terms" data-role="slider" data-mini="true">
                            <option name = "terms" value="n">Deny</option>
                            <option name = "terms" value="y">Agree</option>
                        </select>
                    </div>
                   
                    </div>
                    <div data-role="fieldcontain">
                        <input type="submit" name = "register" value="Send"/>
                    </div>
            </form>

And here is my PHP file

<?php

if(isset($_POST['register'])){
    $fullname = $_POST['fullname'];
    $phonenumber = $_POST['phonenumber'];
    $email = $_POST['email'];
    $gender = $_POST['gender'];
    $location = $_POST['location'];
    $title = $_POST['title'];
    $description = $_POST['description'];
    $image = $_POST['image'];
    $terms = $_POST['terms'];

    //database connection
    $conn = new mysqli('localhost','root','','reportapp');

    //check connection
    if($conn->connect_error){
        die('connection failed'.$conn->connect_error);
        echo "report failed";
    } else{
        $stmt = $conn->prepare("insert into trials(fullname,phonenumber,email,gender,location,title,description,image,terms) 
                values (?,?,?,?,?,?,?,?,?) ");
            $stmt->bind_param("sisssssbs", $fullname, $phonenumber, $email,$gender, $location, $title, $description, $image, $terms)    ;
        
        $stmt->execute();
        echo "case report success.....";
        $stmt->close();
        $conn->close();
    }
}
?>

When ever i upload the data, it does not display the successfully message but only show a blank white page and the data is not inserted into thee database please help me how i can successfully upload the form data to the database!

  • 1
    Hint: "the page loads but does not display anything " usually means you have a server error, so find out where your PHP error logs are and look at the end for details. – tadman Aug 03 '22 at 19:13
  • `var_dump($_POST['image'])` gives what back? I've never stored images as blobs but I think you should be accessing as `$_FILES..` Also, if these are videos it likely is a much better idea to not store in DB but rather store on file system and store location in DB. – user3783243 Aug 03 '22 at 19:21
  • @tadman, i have never worked with php this is my first time and i dont know where i can find my php error logs. – thattCharles Aug 03 '22 at 19:31
  • @user3783243, i dont get any feedback after the page not displaying anything on the screen. i am accessing them as `$_FILES` yes, but nothing is happending – thattCharles Aug 03 '22 at 19:32
  • 1
    You're going to need to find them, or you're operating in the dark here. The documentation should be illuminating. – tadman Aug 03 '22 at 19:33
  • 1
    [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display?rq=1) might help in finding out what went wrong – brombeer Aug 03 '22 at 20:18

0 Answers0