Link to home
Start Free TrialLog in
Avatar of pc-buddy
pc-buddy

asked on

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
Avatar of pc-buddy
pc-buddy

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've requested that this question be deleted for the following reason:

sorted
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.
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).