Php Database INSERT Error

Hi,

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:

<?php

    /* 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());

    }

$date=$_REQUEST['date'];
$activity1=$_REQUEST['activity1'];
$activity2=$_REQUEST['activity2'];
$activity3=$_REQUEST['activity3'];
$activity4=$_REQUEST['activity4'];
$gactivity=$_REQUEST['gactivity'];
$tose=$_REQUEST['tose'];
$news=$_REQUEST['news'];
$fs=$_REQUEST['fs'];

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

        echo "Records added successfully.";

    } else{

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

    }

     

    // Close connection

    mysqli_close($link);

    ?>

Thanks Simon
database.jpg
pc-buddyAsked:
Who is Participating?
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
0
Dan CraciunIT ConsultantCommented:
mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )

Both link and query are required: https://php.net/manual/en/mysqli.query.php

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

HTH,
Dan
0

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:

sorted
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Dan CraciunIT ConsultantCommented:
0
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.
0
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).
0
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
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.