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['acti vity1'];
$activity2=$_REQUEST['acti vity2'];
$activity3=$_REQUEST['acti vity3'];
$activity4=$_REQUEST['acti vity4'];
$gactivity=$_REQUEST['gact ivity'];
$tose=$_REQUEST['tose'];
$news=$_REQUEST['news'];
$fs=$_REQUEST['fs'];
// Attempt insert query execution
$sql = "INSERT INTO Data VALUES ('','','$activity1',$activ ity2','$ac tivity3',$ activity4' ,'$gactivi ty','$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
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"
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$date=$_REQUEST['date'];
$activity1=$_REQUEST['acti
$activity2=$_REQUEST['acti
$activity3=$_REQUEST['acti
$activity4=$_REQUEST['acti
$gactivity=$_REQUEST['gact
$tose=$_REQUEST['tose'];
$news=$_REQUEST['news'];
$fs=$_REQUEST['fs'];
// Attempt insert query execution
$sql = "INSERT INTO Data VALUES ('','','$activity1',$activ
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've requested that this question be deleted for the following reason:
sorted
sorted
The question already has a working solution posted.
https://www.experts-exchange.com/questions/28676854/Php-Database-INSERT-Error.html?anchorAnswerId=40787042#a40787042
https://www.experts-exchange.com/questions/28676854/Php-Database-INSERT-Error.html?anchorAnswerId=40787042#a40787042
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.
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:
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).
$sql = 'INSERT INTO employee (emp_name, emp_address, emp_salary, join_date) VALUES ( "guest", "XYZ", 2000, "' . date("Y-m-d H:i:s") . '")';
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).
ASKER
$sql = 'INSERT INTO employee '.
'(emp_name,emp_address, emp_salary, join_date) '.
'VALUES ( "guest", "XYZ", 2000, NOW() )';
but with my values
same error