The connection and setting are fine as I can insert things into the same db with different tables.

Long story short below is the value that I want to insert into the db but it give me no error and nothing insert. I have use the echo and checked every field have a value...

"data"
    1   id  int(6)          No  None    AUTO_INCREMENT  
    2   title   varchar(80)     latin1_swedish_ci       No          
    3   docname     varchar(80)     latin1_swedish_ci       No          
    4   version     varchar(10)     latin1_swedish_ci       No  None        
    5   Categroy    varchar(30)     latin1_swedish_ci       No  None        
    6   Sub_Categroy    varchar(30)     latin1_swedish_ci       No  None        
    7   Author  varchar(50)     latin1_swedish_ci       No  None        
    8   approval    enum('approved', 'pending')     latin1_swedish_ci       No  None        
    9   documentdir     varchar(100)    latin1_swedish_ci       No  None        
    10  description     longtext    latin1_swedish_ci       No  None        
    11  type    varchar(20)     latin1_swedish_ci       No          
    12  size    varchar(20)     latin1_swedish_ci       No          
    13  Updated_by  varchar(80)     latin1_swedish_ci       No          
    14  md5hash     varchar(32)     latin1_swedish_ci       No          ctions More
    15  Delete  enum('0', '1')  latin1_swedish_ci       No  None        
    16  date_added  datetime

$title = trim($_SESSION['title']);
$docname = trim($_SESSION['docname']);
$Categroy = trim($_SESSION['Categroy']);
$Sub_Categroy = trim($_SESSION['Sub_Categroy']);
$author = trim($_SESSION['author']);
$docdir = trim($_SESSION['docdir']);
$description = trim($_SESSION['description']);
$size = trim($_SESSION['size']);
$type = trim($_SESSION['type']);
$md5 = trim($_SESSION['md5']);
$approval = trim($_SESSION['approval'] );
$version = trim($_SESSION['version'] );
$tempfile = trim($_SESSION['tempfile'] );
$Delete = 0;
$user=$_SESSION['user'];
$date = DATE('Y-m-d H:i:s');


$query = "INSERT INTO data (id, title, docname, version, Categroy, Sub_Categroy, Author, approval, documentdir, description, type, size, Updated_by, md5hash, Delete, date_added)
VALUES ('', '$title', '$docname', '$version', '$Categroy', '$Sub_Categroy', '$author', '$approval', '$docdir', '$description', '$type', '$size', '$user', '$md5', '$Delete', '$date')";
$results = mysql_query($query);

echo $title."</br>";
echo $docname."</br>";
echo $Categroy."</br>";
echo $Sub_Categroy."</br>";
echo $author."</br>";
echo $docdir."</br>";
echo $description."</br>";
echo $size."</br>";
echo $type."</br>";
echo $md5."</br>";
echo $approval."</br>";
echo $version."</br>";
echo $Delete."</br>";
echo $user."</br>";
echo $date."</br>";

after the echo, I got below result. But nothing insert into the table

Research Project
project.V1.3.02-07-2012.pdf
Type A
Small
8080
IT773
Research Project Report
932.424
pdf
e89eeb337b7895020eddb49ddf91f489
approved
V1.3
0
8080
2013-05-06 17:19:02

Ive checked the spelling but seem to be there is no mistake...I think I have a small mistake somewhere but just couldnt locat it...
thanks

I think the '', at the beginning of VALUES need'nt be there.

I need it to adjecnt the value to match the correct row.

but anyway just give it a try and no luck

Have tried took away the '', at the beginning and the id
and took away the '', alone...

no luck so far.

Ok...I found where is the mistake...

The resaon why it is not inserting its because of I have a coloum called 'Delete' and sql read as a SQL syntax error...for some reason it didnt give me any error message so I went to the sql and run that code and it give me this.

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Delete'

I rename the coloum and it is now working fine.
Took me almost an hour to figure it out...as I forgot that I can put this code in the SQL to run...and it can give me the error right away...

remove id filed as it is autoincrement
So your query should look something like this

$query = "INSERT INTO data (title, docname, version, Categroy, Sub_Categroy, Author, approval, documentdir, description, type, size, Updated_by, md5hash, Delete, date_added)
VALUES ('$title', '$docname', '$version', '$Categroy', '$Sub_Categroy', '$author', '$approval', '$docdir', '$description', '$type', '$size', '$user', '$md5', '$Delete', '$date')";
$results = mysql_query($query);

If that doesn't work,check if date_added and $date are of same type as it seems one is string and another is DateTime.

the problem is I have a coloum called 'Delete' and sql read as a SQL syntax error

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Delete'

rename the field and the my code is now working.

thanks for the help.

You could just have enclosed delete in backticks, instead of renaming the column.

what you mean backticks?

INSERT INTO `data` (`title`, ..., `delete`, `date_added`) ...

The backticks mark table and column names, so you can safely use reserved words.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.