Jump to content

[SOLVED] Problem with my INSERT statement


rondog

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/70684-solved-problem-with-my-insert-statement/
Share on other sites

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();
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.