Jump to content

file upload


searls03

Recommended Posts

I have this code:

<?php
if($_POST['submit']){
// Where the file is going to be placed
$target_path = "images/".$_SESSION['username']."/";

foreach ($_FILES["uploadedfile"]["name"] as $key => $value) {
$uploadfile = $target_path . basename($_FILES[uploadedfile][name][$key]);
//echo $uploadfile;
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$key], $uploadfile)) { 
echo $value . ' uploaded<br>'; }
}

}

?>

and I want to insert:

 $sql = mysql_query("UPDATE pics SET link='$target_path' WHERE id='$userid1'")or die(mysql_error());

so that when it uploads the file, it will also put info, such as a link to the file in the dbase.  how can I make $target_path = "images/".$_SESSION['username']."/ (the name of the file)"; I am stumped as to where to put the code or how to do this.  please help.

Link to comment
Share on other sites

I have this and it still does not update database, it uploads though........

<?php
if($_POST['submit']){
// Where the file is going to be placed
$target_path = "images/".$_SESSION['username']."/";

foreach ($_FILES["uploadedfile"]["name"] as $key => $value) {
$uploadfile = $target_path . basename($_FILES[uploadedfile][name][$key]);
//echo $uploadfile;
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$key], $uploadfile)) {  $sql = mysql_query("UPDATE pics SET link='$target_path', name='$uploadedfile'  WHERE id='$userid1'")or die(mysql_error());
echo $value . ' uploaded<br>'; }
}

}

?>

Link to comment
Share on other sites

I have this and it still does not update database, it uploads though........

<?php
if($_POST['submit']){
// Where the file is going to be placed
$target_path = "images/".$_SESSION['username']."/";

foreach ($_FILES["uploadedfile"]["name"] as $key => $value) {
$uploadfile = $target_path . basename($_FILES[uploadedfile][name][$key]);
//echo $uploadfile;
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$key], $uploadfile)) {  $sql = mysql_query("UPDATE pics SET link='$target_path', name='$uploadedfile'  WHERE id='$userid1'")or die(mysql_error());
echo $value . ' uploaded<br>'; }
}

}

?>

 

Can you print your query on screen, if you get correct value then you should identify some other problem.

I think, your query should be

$sql = mysql_query("UPDATE pics SET link='".$target_path."', name='".$uploadedfile."'  WHERE id='".$userid1."'")or die(mysql_error()); 

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.