Php Database INSERT Error


Cant seem to enter data into my database, database setup attached, code below

my error message is: ERROR: Could not able to execute INSERT INTO Data VALUES ('','','f',f','f',f','f','','','').

the code:


    /* Attempt MySQL server connection. Assuming you are running MySQL

    server with default setting (user 'root' with no password) */

    $link = mysqli_connect("localhost", "astonpie_baby", "******", "astonpie_baby");

    // Check connection

    if($link === false){

        die("ERROR: Could not connect. " . mysqli_connect_error());



    // Attempt insert query execution
      $sql = "INSERT INTO Data VALUES ('','','$activity1',$activity2','$activity3',$activity4','$gactivity','$tose','$news','$fs')";

        echo "Records added successfully.";

    } else{

        echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);



    // Close connection



Thanks Simon
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pc-buddyAuthor Commented:
i have also tried the insert like this

$sql = 'INSERT INTO employee '.
       '(emp_name,emp_address, emp_salary, join_date) '.
       'VALUES ( "guest", "XYZ", 2000, NOW() )';

but with my values

same error
Dan CraciunIT ConsultantCommented:
mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )

Both link and query are required:

  if(mysqli_query($link, $sql)){


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pc-buddyAuthor Commented:
I've requested that this question be deleted for the following reason:

Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Dan CraciunIT ConsultantCommented:
Dan CraciunIT ConsultantCommented:
That's a continuation.
The OP did not take my solution, he switched to mysql_ instead (which is bad, but it got rid of the error), then kept the code after that, which of course did not work, because mysql_  works with arrays, not objects.
Martin FernandezCommented:
Just in case, try:

$sql = 'INSERT INTO employee (emp_name, emp_address, emp_salary, join_date) VALUES ( "guest", "XYZ", 2000, "' . date("Y-m-d H:i:s") . '")';

Open in new window

Because now() is a SQL function and may not work in PHP callback. You can use date() that creates a date-format string (accepted by MySQL).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.