Jump to content

Recommended Posts

Ok, I don't know if I am doing this right but and help would be great, I am still very green @ php. below you will find my code. In this page I have established a database connect already. the file uploads perfectly with my new name. My real question is how can I put my new file name in my database form my variable $newName. What would be the proper code to do this?

 

 

<?php

 

// Generate Random Number

srand(time());

$random = (rand()%99999999);

 

// Add Random Number to First of File Name

$newName="$random"."_"."$file_name";

 

// Copy to Fold Append New File Name

if($file_name !="")

{

copy ("$file", "images_upload/$newName")

or die ("could not copy file");

}

else { die(); }

 

//DISPLAY INPUT/OUTPUT

echo"Old File Name is: $file_name<br>";

echo"File Size is: $file_size<br>";

echo"File Type is: $file_type<br>";

echo"Random Number is: $random<br>";

echo"New File Name is: $newName";

?>

You really should put all code inside the [ code ] [ /code ] tags.

 

One way (I am just creating this in my head since you did not post any SQL what so ever) is this:

 

<?php
// mysql connection started

mysql_query("UPDATE tabl_name SET filename = '".$newName."' WHERE fileid = '".$fileid."'");

?>

 

This is assuming you have a fileid in the database to identify the file, if not put your identification field there. Either way that is how you update a field using MySQL.

 

--FrosT

Here is my SQL code, can you tell me why it is not working

 

 

<?php require_once('Connections/siteData.php'); ?>

<?php

mysql_select_db($database_siteData, $siteData);

$query_Recordset1 = "SELECT * FROM images";

$Recordset1 = mysql_query($query_Recordset1, $siteData) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

 

mysql_query("INSERT INTO images VALUES ('$newNmae')");

 

?>

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.