grozanc Posted March 6, 2008 Share Posted March 6, 2008 Hello All, I'm trying to create a page that lets people who submitted photos to a website go back in and edit the information they submitted. I got the script to go back in and successfully change the submitted information if they also submit a new photo. If they change everything but the photo the script errors out. My thinking was to use the if statement to have one action happen if the file input field is blank, and a second action if the file input field has information. I think the problem is how I'm trying to triggr the if statement. I've also included the form code as well. Any ideas? where I think the problem is $hasPortrait = false; if ($_FILES['userfile']['name'] != "") { $hasPortrait = true; } if ($hasPortrait = false) { action #1} else {action #2} fullcode <?php $host = 'localhost'; $user = 'xxxxxx'; $pass = 'xxxxxx'; $db = 'xxxxxx'; mysql_connect($host,$user,$pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); // Set variables $hasPortrait = false; if ($_FILES['userfile']['name'] != "") { $hasPortrait = true; } // you can change this to any directory you want // as long as php can write to it $uploadDir = 'photos/'; $home_path = '/home/grozanc/public_html/pavementmemories/'; // Set maximum sizes for resized images. $maxWidth = 375; $maxHeight = 250; $maxWidth2 = 75; $maxHeight2 = 75; $fileName = $_FILES['userfile']['name']; if ($hasPortrait = false) { // Set variables $id=$_POST['id']; $first_name = $_POST['first_name']; $email = $_POST['email']; $city = $_POST['city']; $state = $_POST['state']; $link = $_POST['link']; $caption = $_POST['caption']; $thanks = $_POST['thanks']; // Insert into database $query = "UPDATE uploads_content SET first_name = '$first_name', email = '$email', city = '$city', state = '$state', link = '$link', caption = '$caption', approved = '0' WHERE id = '$id' "; mysql_query($query) or die('Error, query failed : ' . mysql_error()); } else { $id=$_REQUEST['id']; if(isset($_POST['upload'])) { $first_name = $_POST['first_name']; $email = $_POST['email']; $city = $_POST['city']; $state = $_POST['state']; $link = $_POST['link']; $caption = $_POST['caption']; $thanks = $_POST['thanks']; $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; // get the file extension first $ext = substr(strrchr($fileName, "."), 1); // generate the random file name $randName = md5(rand() * time()); // and now we have the unique file name for the upload file $filePath = $uploadDir . $randName . '.' . $ext; $filePathResized = $uploadDir . $randName . '.sized.' . $ext; $filePathThumb = $uploadDir . $randName . '.thumb.' . $ext; // move the files to the specified directory // if the upload directory is not writable or // something else went wrong $result will be false $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } else { $size=getimagesize($filePath); if ($size[0]>$maxWidth or $size[1]>$maxHeight) { $result2 = @exec("/usr/bin/convert -geometry '" . $maxWidth . "x" . $maxHeight . ">' $filePath $filePathResized"); # echo $result2; } { $result3 = @exec("/usr/bin/convert -geometry '" . $maxWidth2 . "x" . $maxHeight2 . ">' $filePath $filePathThumb"); # echo $result3; } } if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $query2 = 'UPDATE uploads_content SET first_name = "' . $first_name . '" , email = "' . $email . '" , city = "' . $city . '" , state = "' . $state . '" , caption = "' . $caption . '" , name = "' . $fileName . '" , size = "' . $fileSize . '" , type = "' . $fileType . '" , path = "' . $filePath . '" , sized = "' . $filePathResized . '" , thumb = "' . $filePathThumb . '" , approved = "' . 0 . '" where id=' . $id; mysql_query($query2) or die('Error, query failed : ' . mysql_error()); } include 'thanks.php'; } ?> Form Code <form action="edit_photoscript.php " method="post" enctype="multipart/form-data" name="uploadform"> <font class="forms">First Name:<br> <input value="<?=$row['first_name']?>" type="text" name="first_name" id="first_name" class="story"/> <br><br> E-Mail:<br> <input value="<?=$row['email']?>" type="text" name="email" id="email" class="story"/> <br><br> <a href="javascript:openCityStatePhotoWindow();" class="linkpopup">City & State:<br></a> <input value="<?=$row['city']?>" type="text" name="city" id="city" class="storycity"/> <? include 'library/state1edit.php'; ?> <br><br> <a href="javascript:openLinksWindow();" class="linkpopup">Web Link:<br></a> <input value="<?=$row['link']?>" type="text" name="link" id="link" class="story"/> <br><br> <a href="javascript:openPhotoWindow();" class="linkpopup">Photo:<br></a> <img src='<?=$row['thumb']?>'><br> <input name="userfile" type="file" id="userfile" class="storyphoto"> <br><br> <a href="javascript:openCaptionPhotoWindow();" class="linkpopup">Photo Caption:<br></a> </font> <textarea name="caption" id="caption" wrap="hard" class="storycaption"><?=$row['caption']?></textarea><br> <br><br> <input type="hidden" name="thanks" value="6"> <input type="hidden" name="id" value="<?=$row['id']?>"> <input name="upload" type="submit" id="upload" value="Upload" class="storybtn" onClick="YAHOO.example.container.wait.show();"> </form> Quote Link to comment Share on other sites More sharing options...
grozanc Posted March 6, 2008 Author Share Posted March 6, 2008 Any ideas on how to fix this or can someone see the problem? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 6, 2008 Share Posted March 6, 2008 This "if" statement is wrong <?php if ($hasPortrait = false) { action #1} ?> The single "=" is used for assignment, not comparison. Since you're using the boolean "true" and "false", you can write <?php if (!$hasPortrait) { action #1} ?> Ken Quote Link to comment Share on other sites More sharing options...
grozanc Posted March 6, 2008 Author Share Posted March 6, 2008 Thanks Ken, That solved the problem! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.