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
https://forums.phpfreaks.com/topic/244294-file-upload/
Share on other sites

$sql = "INSERT INTO tableName  (imageName, userid)  VALUES('" .$uploadfile ."','" .$_SESSION['username']."')";

http://www.w3schools.com/PHP/php_mysql_insert.asp

 

You're simply doing all the work for him, let him learn and try it before asking us to type for him.

 

P.S, Stay away from w3schools.

Link to comment
https://forums.phpfreaks.com/topic/244294-file-upload/#findComment-1254751
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
https://forums.phpfreaks.com/topic/244294-file-upload/#findComment-1257869
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
https://forums.phpfreaks.com/topic/244294-file-upload/#findComment-1257986
Share on other sites

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.