I cant insert my data in the database. PLS help me!

epiz_31134436 is my username and my website is this one pesospc.epizy.com

I am making a system which will be presented at my professors on Friday and I finished coding in xampp and my codes has perfectly executed the system locally (phpmyadmin)
so my adviser said that I should post it on a free webhosting website. When I uploaded the php files, I changed the dbname, password, hostname and the user on my functions.php and I also import my sql into the new DB from here.

functions.php

<?php
    define('DBINFO','mysql:host=XXXXXXX;dbname=epiz_XXXXXXXXX');
    define('DBUSER','epiz_31134436');
    define('DBPASS','XXXXXXXXXXXX');


    function performQuery($query){
        $con = new PDO(DBINFO,DBUSER,DBPASS);
        $stmt = $con->prepare($query);
        if($stmt->execute()){
            return true;
        }else{
            return false;
        }
    }

    function fetchAll($query){
        $con = new PDO(DBINFO, DBUSER, DBPASS);
        $stmt = $con->query($query);
        return $stmt->fetchAll();
    }

?>

Everything went smoothly on the admin panel, whatever I uploaded data in the local I can see them (Graphs list of student etc.). But the problem here is when I go to registering a new student, I can’t add anymore in signup.php. I may have change a few things in here but what could have gone wrong in this file? Please let me know. I’m really tired fixing this one knowing my group mates cant help me.

I can’t understand your problem, can u send a screenshot??

Im sorry, I am having a trouble pasting the code.

Here is my functions.php

<?php
    define('DBINFO','mysql:host=sql100.epizy.com;dbname=epiz_31134436_XXXXX');
    define('DBUSER','epiz_31134436');
    define('DBPASS','XXXXXXXXX');


    function performQuery($query){
        $con = new PDO(DBINFO,DBUSER,DBPASS);
        $stmt = $con->prepare($query);
        if($stmt->execute()){
            return true;
        }else{
            return false;
        }
    }

    function fetchAll($query){
        $con = new PDO(DBINFO, DBUSER, DBPASS);
        $stmt = $con->query($query);
        return $stmt->fetchAll();
    }

?>

Where is the $query variable?

1 Like

this one from the signup.php

<?php
      include("functions.php");

        if(isset($_POST['signup'])){
            $firstname = $_POST['firstname'];
            $lastname = $_POST['lastname'];
            $email = $_POST['email'];

            $father = $_POST['father'];
            $mother = $_POST['mother'];
            $gender = $_POST['gender'];
            $birthday = $_POST['birthday'];
            $phone = $_POST['phone'];
            $address = $_POST['address'];
            $zipcode = $_POST['zipcode'];

            $school = $_POST['school'];
            $course = $_POST['course'];
            $idcard = $_POST['idcard'];
            $year = $_POST['year'];
            $sem = $_POST['sem'];
            $ay = $_POST['ay'];

            $company = $_POST['company'];
            $position = $_POST['position'];
            $industry = $_POST['industry'];
            $message = "$lastname $firstname would like to request an account.";

           

            $query = "INSERT INTO `requests` (`id`, `u_f_name`, `u_l_name`, `u_email`, `u_father`, `u_mother`, `u_gender`, `u_birthday`, `u_phone`, `u_address`, `u_zipcode`, `u_school`, `u_course`, `u_card`, `u_year`, `u_sem`, `u_ay`, `u_company`, `u_position`, `u_industry`,  `uploaded`, `message`) 
            VALUES ('NULL', '$firstname', '$lastname', '$email', '$father', '$mother', '$gender','$birthday','$phone','$address', '$zipcode','$school','$course','$idcard', '$year', '$sem', '$ay', '$company', '$position', '$industry', CURRENT_TIMESTAMP, '$message')";
            $worked= mysqli_query($db,$query); 

            if (!$worked) { echo "Error : cannot add to daabase"; } else { echo "no problem"; } 

        }

    ?>```

Enable PHP errors, Then share the screenshot of the error.

I looked at signup.php and functions.php, but it looks like signup.php doesn’t do anything with the functions from functions.php.

In functions.php, you’re making custom functions which make database queries with PDO.

But in signup.php, you’re calling mysqli_query($db,$query);. But that’s using a completely different database module, it’s using mysqli instead of pdo. And you’re passing the variable $db to it, and I don’t see where this variable is being defined, or how it’s being defined.

I’m surprised that this code could work at all, and if it did it could only have been done by threading the needle of coincidence, not by writing correct code.

That’s something you should be working on. I could give you more detailed instructions, but it sounds like you’re doing this as a school assignment, and I’m not going to do your homework for you.

5 Likes

Ohh I see now, I forgot to put $db = mysqli_connect('sql100.epizy.com', 'epiz_31134436', 'xxxxxxxxxxxx', 'epiz_31134436_xxxxxx');

I typed it in but still it doesn’t work. Sir/Ma’am I apologize if I might not be able to reply for now coz I am a working-student here in the Philippines and I should be off on my bed right now, I feel exhausted. :yawning_face: :weary:

1 Like

Thank you for the guide anyway. :grin:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.