rondog Posted September 25, 2007 Share Posted September 25, 2007 I am looping around a directory of flv's. and trying to inserting them into a database. I just created it and it contains fields like so: camera,tape,vidname,client,title,segtitle,location,dateshot,rights,keywords,comments,rating. I am leaving the remaining fields blank after vidname. My code is as follows: <?php include 'connect.php'; $camera = "cam_a"; $tape = "tape_1"; $dir = opendir ("../$camera/$tape"); while (false !== ($file = readdir($dir))) { if (strpos($file, '.flv',1)) { $s .= "('$camera','$tape','".$file."'), "; } } $sql = "INSERT INTO videos (camera,tape,vidname) VALUES ".$s; $sret = substr($sql, 0, count($sql)-3); //echo $sret; $query = mysql_query($sret); ?> If I echo out $sret I get the following: INSERT INTO videos (camera,tape,vidname) VALUES ('cam_a','tape_1','a3-t1-001.flv'), ('cam_a','tape_1','a3-t1-002.flv'), ('cam_a','tape_1','a3-t1-003.flv'), ('cam_a','tape_1','a3-t1-004.flv'), ('cam_a','tape_1','a3-t1-005.flv'), ('cam_a','tape_1','a3-t1-006.flv'), ('cam_a','tape_1','a3-t1-007.flv'), ('cam_a','tape_1','a3-t1-008.flv'), ('cam_a','tape_1','a3-t1-009.flv'), ('cam_a','tape_1','a3-t1-010.flv'), ('cam_a','tape_1','a3-t1-011.flv'), ('cam_a','tape_1','a3-t1-012.flv') When I try and run $query, it doesn't do anything. Nothing is inserted and I do not get any errors. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/70684-solved-problem-with-my-insert-statement/ Share on other sites More sharing options...
rondog Posted September 25, 2007 Author Share Posted September 25, 2007 oh this is my connect script by the way <?php $con = mysql_connect("localhost","username","password"); if (!$con) { echo "unable to connect to DB"; echo mysql_error($con); exit(); } $db = mysql_select_db("theDB"); if (!$db) { echo "unable to open DB"; echo mysql_error($db); exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70684-solved-problem-with-my-insert-statement/#findComment-355272 Share on other sites More sharing options...
suttercain Posted September 25, 2007 Share Posted September 25, 2007 try this, you don't have errors on.. so you won't see any: $query = mysql_query($sret) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/70684-solved-problem-with-my-insert-statement/#findComment-355279 Share on other sites More sharing options...
rondog Posted September 25, 2007 Author Share Posted September 25, 2007 ahh gotcha I fixed it thanks Quote Link to comment https://forums.phpfreaks.com/topic/70684-solved-problem-with-my-insert-statement/#findComment-355300 Share on other sites More sharing options...
darkfreaks Posted September 25, 2007 Share Posted September 25, 2007 topic solved plz? Quote Link to comment https://forums.phpfreaks.com/topic/70684-solved-problem-with-my-insert-statement/#findComment-355301 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.