wrathican Posted July 10, 2007 Share Posted July 10, 2007 hey guys. i hope u can help me. the problem i have is that when i show the form (case "modal":)i change the title, the description and add a new image so that the new image will be used as the title image for that album it doesnt seem to see that $_POST['image'] is set and doesnt execute the piece of code in the first part of the IF statement it just does the ELSE part. any ideas/suggestions as to why will be greatly appreciated. oh and im not posting my full code because theres like 450 lines and the rest of it works case "modal": $alid = $_GET['alid']; //shows form to modify a selected album $query = "SELECT * FROM cy_album WHERE al_id='".$alid."'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $alid = $row[0]; $title = $row[1]; $image = $row[3]; $description = $row[2]; }; //show form with echoed variables ?> <form action="galleryadmin.php?func=processalmod&alid=<?php echo $alid; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1"> Album Title:<br /> <input name="title" type="text" id="title" value="<?php echo $title; ?>"/> <br /> Title Image:<br /> <img width="500" src="../images/gallery/<?php echo $image; ?>"><br /> Album Description: <br /> <textarea name="description" cols="50" rows="10" id="description"><?php echo $description; ?></textarea> <br /> New Image:<br /> <input name="image" type="file" id="image" /> <br /> <br /> <input type="hidden" name="alid" value="<?php echo $alid; ?>" /> <input type="hidden" name="oldimagename" value="<?php echo $image; ?>" /> <input type="hidden" name="MAX_FILE_SIZE" value="2000000" /> <input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /> <br /> </form> <?php break; case "processalmod": $title = $_POST['title']; $description = $_POST['description']; $alid = $_POST['alid']; $oldimage = $_POST['oldimagename']; //if statement determines whether or not to unpload the new picture based on whether $_POST['image'] is set if(isset($_POST['image']) && $_POST['image']['size'] <= $_POST['MAX_FILE_SIZE']) { //another if statement to see if the delete is sucessful $result = unlink("../images/gallery/" . $oldimage); if(!$result) { echo "Error deleting file."; exit; } $fileName = $_FILES['image']['name']; $tmpName = $_FILES['image']['tmp_name']; $ext = substr(strrchr($fileName, "."), 1); // make the random file name $randName = md5(rand() * time()); // and now we have the unique file name for the upload file $filePath = '../images/gallery/' . $randName . '.' . $ext; $move = move_uploaded_file($tmpName, $filePath); if(!$move){ echo "Error uploading file"; exit; } $imagepath = $randName . '.' . $ext; if(!get_magic_quotes_gpc()) { $title = addslashes($title); $imagepath = addslashes($imagepath); $description = addslashes($description); } $query = "UPDATE cy_album SET al_name='$title', al_description='$description', al_image='$imagepath' WHERE al_id='$alid'"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); echo "Thank you, the new image, title and description has been replaced."; }else{ //use UPDATE to update the posted values if(!get_magic_quotes_gpc()) { $title = addslashes($title); $description = addslashes($description); } $query = "UPDATE cy_album SET al_name='$title', al_description='$description' WHERE al_id='$alid'"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); echo "Thank you the Album title and description has been updated."; } break; Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 10, 2007 Share Posted July 10, 2007 Ive never seen: $result, MYSQL_NUM So I can't say if thats right or wrong. But I do know you have an extra ";" at the end of your while statemnt take it out. Ill look over it more later im hungery. Quote Link to comment Share on other sites More sharing options...
wrathican Posted July 10, 2007 Author Share Posted July 10, 2007 $result, MYSQL_NUM this tells php to create the array as a numerical array so that the values go 0,1,2,3, etc... i find it easier than associative arrays, having to type the name of the columns all the time... but the form is absolutely fine, i think, unless its not posting the image to the page the theres something wrong. am i right in thinking that 2,000,000bytes is almost 2 Mb? and that the size in specifying is that? because if not then thats most likely my problem... Quote Link to comment Share on other sites More sharing options...
wrathican Posted July 11, 2007 Author Share Posted July 11, 2007 ok, would changing the if statement around help? so that the else part goes in at the beggining? and the if statement starts like so: if (!$_POST[image']) { //else block }else{ //if block } Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 2,097,152 is 2MB Quote Link to comment Share on other sites More sharing options...
wrathican Posted July 11, 2007 Author Share Posted July 11, 2007 ah yeah, so i was near enough. and its not like my image is too big then.... hmmmmm Quote Link to comment Share on other sites More sharing options...
wrathican Posted July 11, 2007 Author Share Posted July 11, 2007 ok so that did not help. can any of you guys suggest how to do this? what i want is a scripts that recieves a form. the form contains the following: -the album ID, so as to know which album to update. -the new album title -the new album description -the new title image for that album (if the user selected a new image) the script is going to do the following: -receive the form data and put them into variables -detect to see if the user selected a new image for the album. --if not just update the db with the new title and description --if so, delete the old image ---if that is sucessful move on --upload the new image to the server --insert the new image name, title and description -echo a message to say that its done please please please help me i cannot get it to work for the life in me 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.