So I'm trying to transfer a longblob from one data table to another. All the other data is transferring however the longblob isn't. I know it is getting up loaded to the temp table because the longblob column show s there is data in it.

here is the snippet of code i'm using to upload the data (connection info removed)

$link = mysql_connect($host, $username, $password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

mysql_select_db ($database); 
 
$confirmcode = md5(uniqid(rand()));
$title = $_POST ['title'];
$price = $_POST ['price'];
$listdesc = $_POST ['listdesc'];
$email = $_POST ['email'];
$retype = $_POST ['retype'];
$date = date("Y-m-d");

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

      $tmpName  = $_FILES['image']['tmp_name'];  
      $fp      = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);
      


$sql="INSERT INTO temptumisc (confirmcode, title, price, listdesc, email, retype, image , date) VALUES ('".$confirmcode."', '".$title."', '".$price."', '".$listdesc."', '".$email."', '".$retype."', '".$data."', '".$date."')";

$result=mysql_query($sql); 
}

and here is the code for the transfer that isn't working....

<? 
include('connect.php');

$passkey=$_GET ['passkey'];

$tbl_name1="temptumisc";

$sql1="SELECT * FROM $tbl_name1 WHERE confirmcode ='".$passkey."'";

$result1=mysql_query($sql1);

if ($result1){

$count=mysql_num_rows ($result1);

if ($count==1) {

$rows=mysql_fetch_array($result1);
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

      $tmpName  = $_FILES['image']['tmp_name'];  
      $fp      = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);
}

$title = $rows['title'];
$price = $rows['price'];
$listdesc = $rows['listdesc'];
$email = $rows['email'];
$retype = $rows['retype'];

$date = date("Y-m-d");


$tbl_name2="tumisc";

$sql2="INSERT INTO $tbl_name2 (title, price, listdesc, email, retype, image, date) VALUES ('".$title."', '".$price."', '".$listdesc."', '".$email."', '".$retype."', '".$data."', '".$date."')";

$result2=mysql_query($sql2);
}

Last question I asked was answered immediately and I was able to figure it out from there. Hope it'll happen again. Any help or pointers will be greatly apreciated because I am self-teaching.

I can't see any errors though you don't appear to have a mysql_select_db() above your query, and in your sql you can use VALUES ('$title', '$price' ...) instead of VALUES ('".$title."', '".$price."', ...) becase it is all wrapped in double quotes.

try putting in select db above your queries.
are you getting any mysql errors?

thanks for replying but the db selection is within the connect.php. The data transfer for all non longblobs are working but the longblob isn't....there are no mysql errors and all of the data, except for the longblob, are being transferred.

try removing the if statement where the data variable is. see if it works. this ight be the problem as it is the only thing different

Thanks for the help. I tried removing the if statement where the data variables but I still could not get the longblob to transfer. Somehow the data is being lost. I might not be writing it correctly. If you could provide an example of what you think the code should look like it would be apreciated.

Any other ideas of what could be wrong?

Oh just looking at your code through dreamweaver, you are using $_FILES but I don't think the file is actually being uploaded the second time. try using $rows instead.
and your missing a closing brace at the end

<?
include('connect.php');
$passkey=$_GET ['passkey'];
$tbl_name1="temptumisc";
$sql1="SELECT * FROM $tbl_name1 WHERE confirmcode ='".$passkey."'";
$result1=mysql_query($sql1);
if ($result1){
	$count=mysql_num_rows($result1);
	if ($count==1) {
		$rows=mysql_fetch_array($result1);
	$data = $rows['data'];
	$title = $rows['title'];
	$price = $rows['price'];
	$listdesc = $rows['listdesc'];
	$email = $rows['email'];
	$retype = $rows['retype'];
	$date = date("Y-m-d");
	$tbl_name2="tumisc";
	$sql2="INSERT INTO $tbl_name2 (title, price, listdesc, email, retype, image, date) VALUES ('$title', '$price', '$listdesc', '$email', '$retype', '$data', '$date')";
	$result2=mysql_query($sql2);
	}
}
?>

hope this helps

I tried copying your code. The same thing occurs. The other data types, the non-longblob fields, are being moved to the new table but the longblob still isn't. It says that there is 0 K of data. I added the closing brace as well.

I've been trying other things but still no success. Any other suggestions?

sorry I'm a little busy to make another code atm, but first try echoing out the data from the first table and make sure it is being correctly retrieved from the table,
or look at my tutorial on inserting images to a database and see if you can find something useful. i'll have another look at it tonight.

tutorial

Did you ever figure this out? Having the same problem right now.

I got it working. Just have to retrieve the image the same way you get everything else from the table and then just addslashes.

$data = $row;
$data = addslashes($data);

After that it's ready to be inserted into the table just like you did originally.

Did you ever figure this out? Having the same problem right now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.