473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Directory listing to mysql

I followed a set of posts on this site on how to do this but being the noob that I am got stuck :)

My code runs as follows:


<?php
$dbhost = '******';
$dbuser = '******';
$dbpass = '******';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = '******';
mysql_select_db($dbname);

$fol = "./Imgs/images/";
$dir = opendir ($fol);
while (false !== ($file = readdir($dir))) {
if (strpos($file, '.gif',1)||strpos($file, '.jpg',1) ) {
// (This was just for testing) echo "<a href=\"".$fol."".$file."\">".$file."</a><br />";

$query = 'INSERT INTO `******`.`******` (`id`, `pasta`, `nome`) VALUES (NULL, $fol, $file);';
mysql_query($query) or die('Error, insert query failed');
}
}
?>


It gives me 'Error, insert query failed' and I assume it's because of the variables

Can someone help?

PS: The $fol variable exists because it will be eventualy replaced by form variable.

Thanks in advance
Apr 1 '08 #1
4 2702
nitinpatel1117
111 100+
Think you may have the aspostrophes in the wrong place

$query = "INSERT INTO ******.****** (id, pasta, nome) VALUES (NULL, '$fol', '$file');";

try that.
Apr 1 '08 #2
Markus
6,050 Expert 4TB
I followed a set of posts on this site on how to do this but being the noob that I am got stuck :)

My code runs as follows:


<?php
$dbhost = '******';
$dbuser = '******';
$dbpass = '******';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = '******';
mysql_select_db($dbname);

$fol = "./Imgs/images/";
$dir = opendir ($fol);
while (false !== ($file = readdir($dir))) {
if (strpos($file, '.gif',1)||strpos($file, '.jpg',1) ) {
// (This was just for testing) echo "<a href=\"".$fol."".$file."\">".$file."</a><br />";

$query = 'INSERT INTO `******`.`******` (`id`, `pasta`, `nome`) VALUES (NULL, $fol, $file);';
mysql_query($query) or die('Error, insert query failed');
}
}
?>


It gives me 'Error, insert query failed' and I assume it's because of the variables

Can someone help?

PS: The $fol variable exists because it will be eventualy replaced by form variable.

Thanks in advance
Do not [b] your code use [code=xxx] to format it.
If the #2 post doesnt help, try:
[php]
mysql_query($query) or die('Error, insert query failed - ' . mysql_error());
[/php]
Apr 1 '08 #3
thanks, I'm such a noob the 1st one did it.

Will use the code tag from now on

Again thank you
Apr 1 '08 #4
Again, is there a way to recursevly scan al the sub folders inside a main one for the same effect?
Apr 1 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dean | last post by:
Hi I've got a question relating to using Javascript on an Intranet. I have a directory with a list of files in the format week36.xls, week37.xls and I want to write a script that will scan...
19
by: SU News Server | last post by:
I've struggled with this for quite a while and I'm am just not sure what is going on. I have the following code import os def buildList( directory='/Users/mkonrad' ) dirs = listing =...
2
by: Tom | last post by:
I need to get a directory listing through http. If I put the directory path in the browser address bar such as http://somewebpage.com/subdir I get the listing of the directory. Of course this is...
8
by: gil | last post by:
Is it possible to prevent a browser from listing the entire contents of a folder? The site, is hosted on my ISP with the following layout- site/ "user name from ISP" pagefile (dir)...
2
by: ngr | last post by:
I used to use the DirListox control in VB6 but this is no longer supported in VB.NET. What I want to do: I want to take a directory listing and show any subdirectories in a list. When you click...
8
by: dougawells | last post by:
Hi - I'm hoping for help with the auto-generation of a hyperlinked listing of all files in a directory. The server I use does not auto-generate this. So, when someone comes to this directory and...
7
by: epikto | last post by:
I have a mapped share that I am trying to get a listing of all the files that it contains. I use the following code to access the contents String files = Directory.GetFiles(path); I can then...
4
by: techusky | last post by:
I have a *very* simple script written that displays the directory listing of the current working directory, but I am having some difficulty when I try to change folders. Basically, I have my $dir...
2
by: marcusadeleon | last post by:
Hi, I was wondering how to open up a web directory to get a file listing. The directory I want to open allows directory listings, but has a directory password. Meaning it gives me a prompt to...
1
by: Steve | last post by:
My site is hosted on a Godaddy reseller site. Godaddy only allows the use of Curl to access remote sites. What is the method for listing a directory after connecting to the site with Curl? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.