开发者

images won't display after retrieving file location from SQL table using php

开发者 https://www.devze.com 2023-03-10 07:59 出处:网络
Each row in the SQL table represents a user. There are 5 columns related to images: image1, image2, image3, image4, and image5. columns开发者_如何学编程 image[1-5] represent the image file directories

Each row in the SQL table represents a user. There are 5 columns related to images: image1, image2, image3, image4, and image5. columns开发者_如何学编程 image[1-5] represent the image file directories. All the image columns are of the "text" type.

The problem is that when I type in the directory it will display but using the row variable will not work. For example, echo '<img src= "images/img1.jpg" /> '; will display the picture but echo '<img src= "$row[image1]" /> '; where $row['image1'] = "images/img1.jpg" will not work and I will see a torn page icon instead of a picture.

Here is the form script:

<form action="dbpform.php" method="POST" enctype="multipart/form-data">



<input type="text" name="url"><br>

 <input name="uploadedfile1" type="file" /><br />
  <input name="uploadedfile2" type="file" /><br />
   <input name="uploadedfile3" type="file" /><br />
    <input name="uploadedfile4" type="file" /><br />
     <input name="uploadedfile5" type="file" /><br />

<textarea name="comment" id="comment" cols="55" rows="7" wrap="VIRTUAL"></textarea><br>

<input type="submit" name="submit" value="Submit">


</form>

<?php
mysql_connect ("","","") or die(mysql_error());
mysql_select_db ("") or die(mysql_error());

$url = $_POST['url'];
$comment = $_POST['comment'];

$target_path1 = "images/";
$target_path1 = $target_path1 . basename( $_FILES['uploadedfile1']['name']); 

$target_path2 = "images/";
$target_path2 = $target_path2 . basename( $_FILES['uploadedfile2']['name']); 

$target_path3 = "images/";
$target_path3 = $target_path3 . basename( $_FILES['uploadedfile3']['name']); 

$target_path4 = "images/";
$target_path4 = $target_path4 . basename( $_FILES['uploadedfile4']['name']); 

$target_path5 = "images/";
$target_path5 = $target_path5 . basename( $_FILES['uploadedfile5']['name']); 


if ( isset( $_POST['submit'] ) )
{   

move_uploaded_file($_FILES['uploadedfile1']['tmp_name'], $target_path1);
move_uploaded_file($_FILES['uploadedfile2']['tmp_name'], $target_path2);
move_uploaded_file($_FILES['uploadedfile3']['tmp_name'], $target_path3);
move_uploaded_file($_FILES['uploadedfile4']['tmp_name'], $target_path4);
move_uploaded_file($_FILES['uploadedfile5']['tmp_name'], $target_path5);


mysql_query ("INSERT INTO dbp VALUES ('','$url', '$target_path1', '$target_path2','$target_path3','$target_path4','$target_path5','$comment')");            
}

?>

Here is the output script:

<?php

mysql_connect ("","","") or die(mysql_error());
mysql_select_db ("") or die(mysql_error());



$defaultqry = mysql_query ("SELECT * FROM dbp");

while($row = mysql_fetch_assoc($defaultqry))
{


echo $row['comment'];


echo '<img src= "$row[image1]" /> ';
echo '<img src= "$row[image2]" /> ';
echo '<img src= "$row[image3]" /> ';
echo '<img src= "$row[image4]" /> ';
echo '<img src= "$row[image5]" /> ';


echo "<br><br>";


}
?>


You've left out some quotation marks. It's interpreting the image1 in $row[image1] as a constant, probably generating an error message, which is causing your image to show up as not available.

Try something like this:

echo '<img src= "'.$row['image1'].'" /> ';
echo '<img src= "'.$row['image2'].'" /> ';
echo '<img src= "'.$row['image3'].'" /> ';
echo '<img src= "'.$row['image4'].'" /> ';
echo '<img src= "'.$row['image5'].'" /> ';
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号