just created a form that saves the filename into an SQL database.
The thing is that when I ad the ID column(Auto increment) into the SQLDatabase the form stops to save my filename, but as soon I delete the ID row, it begins to save.
Dont know whats the problem.
this is some of my code
<?php
if(isset($_FILES['file_name'])) {
$file_name = mysql_real_escape_string($_FILES['file_name']['name']);
//Writes the information to the database
mysql_query("INSERT INTO `files` VALUES ('$file_name')") ;
}
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM files") or die(mysql_error());
//Puts it into an array
?>
And my database has two columns file_id and file_name
but as I just wrote, the file_id wont work =/
Any ideas ?
I think you need to change your SQL query to this:
With more than one column, you need to name which column you want the
$file_namestring to be saved in if you’re not going to enumerate every column in the table. Then your auto-increment should work fine.In fact, the problem isn’t with auto-increment, it’s with your SQL syntax. You should check your queries for errors by saving the return value from
mysql_queryand checking if it returnedfalse. If it did, callmysql_errorto determine the error message.