Jump to content

Problem with UPDATE cmd / Upload Picture. Help!!


patheticsam

Recommended Posts

Hi! I'm a little bit new to php and I have a little problem and can't seems to find what I'm doing wrong....

 

I have a page where members can upload 2 pictures. The problem is I made a form to modify/change either picture 1, picture 2 or both.

 

Here's the form code :

 

$id=$_GET['id'];

$data = mysql_query("SELECT * FROM artists WHERE artist_id='$id'") 
or die(mysql_error());

while($info = mysql_fetch_array( $data ))

     {

echo "
<center>
<form enctype=\"multipart/form-data\" action=\"processes/modify_photo.php\" method=\"POST\" target=\"main2\">
<input type=\"hidden\" value=\"".$info['artist_id']."\" name=\"id\">
<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"602\">
<tr>
<tr>
<td><h1>Photo 1</h1></td>
<td><h1>Photo 2</h1></td>
</tr>
<td><img src=\"../timthumb.php?src=/admin/artists photo/".$info['photo']."&h=300&w=300&zc=1\" /></td>
<td><img src=\"../timthumb.php?src=/admin/artists photo/".$info['photo2']."&h=300&w=300&zc=1\" /></td>
</tr>
<tr> 
<td>Photo 1</td> 
<td>Photo 2</td> 
</tr> 
<td><input type=\"file\" name=\"uploadedfile\" class=\"login\" style=\"width: 300px\"></td> 
<td><input type=\"file\" name=\"uploadedfile2\" class=\"login\" style=\"width: 300px\"></td> 
</tr> 
</tr> 
<td colspan=\"2\" align=\"center\" height=\"50\"><input type=\"submit\" value=\"Modifier\"></td>  
</tr> 
</table>
</form>

 

As you can see I have two input in wich you can select the picture to upload...The problem is if I only upload 1 picture and decide to keep the same picture for picture 2, MySQL will insert a blank into the picture2 so only the picture I just uploaded will show up (picture 2 won't display cause the value has benn modify to nothing....)

 

So I created an If statement but it dosen't seems to work......Here the update part:

 

<?php
$target_path = "../artists photo/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

$picture = basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "<center><br /><br />votre photo $picture a été correctement enregistré</center><br>";
} else{
    echo "<center><br /><br />Il y a eu un problème avec l'instertion de votre photo</center><br>";
}
?>
<?php
$target_path = "../artists photo/";

$target_path = $target_path . basename( $_FILES['uploadedfile2']['name']); 

$picture = basename( $_FILES['uploadedfile2']['name']);

if(move_uploaded_file($_FILES['uploadedfile2']['tmp_name'], $target_path)) {
    echo "<center><br /><br />votre photo $picture a été correctement enregistré</center><br>";
} else{
    echo "<center><br /><br />Il y a eu un problème avec l'instertion de votre photo</center><br>";
}
?>
<?php
$con = mysql_connect("localhost","login","pass");

$id = $_POST['id'];
$photo = mysql_real_escape_string($_FILES['uploadedfile']['name']);
$photo2 = mysql_real_escape_string($_FILES['uploadedfile2']['name']);




if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("mazemontana", $con);

if ($photo == ' ') {

mysql_query("UPDATE artists SET photo2 = '$photo2' WHERE artist_id = '$id'");

   } else {

mysql_query("UPDATE artists SET photo = '$photo', photo2 = '$photo2' WHERE artist_id = '$id'");
   }
if ($photo2 == ' ') {

mysql_query("UPDATE artists SET photo = '$photo' WHERE artist_id = '$id'");

   } else {

mysql_query("UPDATE artists SET photo = '$photo', photo2 = '$photo2' WHERE artist_id = '$id'");
   }
mysql_close($con);

 

If anyone sees what I'm doing wrong or if you know a better way to do this it would be greatly appreciated!

 

Thanks a lot!

 

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.