karq Posted March 14, 2010 Share Posted March 14, 2010 function if_exist($imgDir,$thumbDir,$datainf){ //Vajalik info include($datainf); $pic = opendir($imgDir); $thumb = opendir($thumbDir); $suva = rand(0,9999); $peakiri = " pilt"; //Code part while (($pics = readdir($pic)) && ($thumbs = readdir($thumb)) ){ if ($pics != ".." && $pics != "." && $thumbs !=".." && $thumbs !="."){ //lets check that the files are in dirs and arent on the database $kontroll = $thumbDir . "/" . $pics; //is in dir if (file_exists($kontroll)){ $kont_dir = true; } else {$kont_dir = false;} //isnt in database $thump = "./".$thumbDir . "/" . $pics; $kont_data = mysql_query("SELECT * FROM pildid WHERE thumbpath = '$thump'",$con) or die (mysql_error()); print $kont_data; if ($kont_data){$kont_base = true;} else { $kont_base = false;} //lets insert when everything is ok $img = "./pildid/".$pics; $thump = "./dPildid/".$pics; if ($kont_dir == true && $kont_base == true){ $add_inf = "INSERT INTO pildid (path,thumbpath) VALUES ('$img','$thump')"; if (!mysql_query($add_inf,$con)) { die("error: " . mysql_error()); } else { echo $pics . " on ylesse laetud!"; } mysql_close($con); } } } } And I get this error: Resource id #8Neljapaev064.JPG on ylesse laetud!Resource id #9Misc004.JPG on ylesse laetud! Warning: mysql_query(): 4 is not a valid MySQL-Link resource in /home/kaarel/progemine/php/fotoleht/admin/function.php on line 77 It insers only 2 picture infos. Link to comment https://forums.phpfreaks.com/topic/195205-php-mysql-query-problem/ Share on other sites More sharing options...
leon_nerd Posted March 14, 2010 Share Posted March 14, 2010 Have you defined $con anywhere? I can see you have used $con but you haven't defined it anywhere. Link to comment https://forums.phpfreaks.com/topic/195205-php-mysql-query-problem/#findComment-1025990 Share on other sites More sharing options...
karq Posted March 14, 2010 Author Share Posted March 14, 2010 include($datainf); $con is defined in the included file Link to comment https://forums.phpfreaks.com/topic/195205-php-mysql-query-problem/#findComment-1026039 Share on other sites More sharing options...
PFMaBiSmAd Posted March 14, 2010 Share Posted March 14, 2010 mysql_close($con); That line of code is inside of the while() loop and it is closing the mysql connection. Link to comment https://forums.phpfreaks.com/topic/195205-php-mysql-query-problem/#findComment-1026041 Share on other sites More sharing options...
karq Posted March 15, 2010 Author Share Posted March 15, 2010 Thanks, that did the trick Link to comment https://forums.phpfreaks.com/topic/195205-php-mysql-query-problem/#findComment-1026249 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.