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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.