Jump to content

Keeping the values if nothing changes?


therelelogo

Recommended Posts

Hi,

 

This is what im having difficulty with - One page allows my user to upload images, the path is saved into a mysql database - this works fine.

Now my new page will allow the user to change the file - effectively changing the path in the database.

 

heres the code i have so far:

			<?php
	// Make a MySQL Connection
mysql_connect("host", "database name", "password") or die(mysql_error());
mysql_select_db("a9203152_adverts") or die(mysql_error());
// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM adverts_business WHERE created_by = '{$_SESSION['SESS_LOGON_NAME']}'") 
or die(mysql_error());  
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
$b_OI1 = $row['image_1'];
$b_OI2 = $row['image_2'];
$b_OI3 = $row['image_3'];
$b_OI4 = $row['image_4'];
} 


//image first
// Where the file is going to be placed 
$target_path = "/home/a9203152/public_html/uploads/business_pics/";
/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile1']['name']); 
$image_location1 = "../../uploads/business_pics/".  basename( $_FILES['uploadedfile1']['name']);
$image_location1_short = "../uploads/business_pics/".  basename( $_FILES['uploadedfile1']['name']);
if(move_uploaded_file($_FILES['uploadedfile1']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile1']['name']). 
    " has been uploaded";
} else{
$image_location1 = "$b_OI1";
$image_location1_short = "../uploads/business_pics/CAno_image.jpg";
    echo "There was an error uploading the file, please try again!";
}
?>

 

okay, so $b_OI1 is the Original Image path for file 1 that is pulled from the database at the start of the code, now as with all my other pages, if there is no file to "move" then the code automatically goes to the "else" statement so in this case $image_location1 should = $b_OI1

 

meaning the new "image location1" equals the original path when nothing has been uploaded yes? but the code removes the path from the database rather than keeping it the same?

 

i hope that makes sence, any help is appreciated

 

Thanks

Link to comment
Share on other sites

Since there's no update command, when you "removes", I assume you mean your php code -- in which case, you're in the wrong board.

 

hi,

 

i have the update command further down in my code, and i know that works because if i change

 

" has been uploaded";} else{	$image_location1 = "$b_OI1";	$image_location1_short = "../uploads/business_pics/CAno_image.jpg";

 

for

 

" has been uploaded";} else{	$image_location1 = $b_OI1;	$image_location1_short = "../uploads/business_pics/CAno_image.jpg";

 

...the value entered into the mysql is $b_OI1 which is not correct. likewise if the user uploads an image the new path is stored, but if no new image is upladed the path stored becomes "" (or nothing, a space, nothing entered - how ever you want to say it). not sure how the php code would be removed?  :wtf: but thats no what was meant by the first post

 

Thanks

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.