Jump to content

Guber-X

Members
  • Posts

    127
  • Joined

  • Last visited

About Guber-X

  • Birthday 12/29/1985

Contact Methods

  • Website URL
    http://www.guberx.com

Profile Information

  • Gender
    Male
  • Location
    Courtenay, BC

Guber-X's Achievements

Member

Member (2/5)

1

Reputation

  1. update got a few more things working, now its the order position not sending value to post. new code: <form method="post"> <?php $pic_query = mysqli_query($con, "SELECT * FROM feature") or die("Pic_Query Failed: ".mysqli_error($con)); while($row = mysqli_fetch_array($pic_query)){ extract($row); ?> <div style="display:inline-block; margin: 4px; padding:5px; border:solid 1px #000000; border-radius:5px;"> <img src="../images/feature/<?php echo $pic ?>" width="200px"> <br>Active: <input type="checkbox" id="act[]" name="act[]" value="<?php echo $id ?>" <?php if($active=='true'){echo 'checked';} ?>> <br> Order: <select id="pos[]" name="pos[]"> <option value="" <?php if($position==NULL){echo 'selected';} ?>></option> <option value="1" <?php if($position=='1'){echo 'selected';} ?>>1</option> <option value="2" <?php if($position=='2'){echo 'selected';} ?>>2</option> <option value="3" <?php if($position=='3'){echo 'selected';} ?>>3</option> <option value="4" <?php if($position=='4'){echo 'selected';} ?>>4</option> <option value="5" <?php if($position=='5'){echo 'selected';} ?>>5</option> </select> <br>Delete: <input type="checkbox" id="checkbox[]" name="checkbox[]" value="<?php echo $id; ?>"> </div> <?php } if($_POST['activate']) { // from button name="delete" $act = $_POST['act']; //from name="checkbox[]" $pos = $_POST['pos']; $countAct = count($_POST['act']); for($n=0;$n<$countAct;$n++) { $act_id = $act[$n]; $pos_val = $pos[$n]; $sql = "UPDATE feature SET position='$pos_val', active='true' WHERE id='$act_id'"; $result = mysqli_query($con, $sql) or die(mysqli_error($con)); } if($result) { print_r($pos_val); //test results echo $act_id."\n"; //test results }else{ echo "Error: ".mysqli_error($con); } } if($_POST['delete']) { // from button name="delete" $checkbox = $_POST['checkbox']; //from name="checkbox[]" $countCheck = count($_POST['checkbox']); for($i=0;$i<$countCheck;$i++) { $del_id = $checkbox[$i]; $del = "SELECT * FROM feature WHERE id='$del_id'"; $delQuery = mysqli_query($con, $del) or die(mysqli_error($con)); while($delrow = mysqli_fetch_array($delQuery)){ extract($delrow); } unlink('../images/feature/'.$pic); $sql = "DELETE FROM feature WHERE id = $del_id"; $result = mysqli_query($con, $sql) or die(mysqli_error($con)); } if($result) { header('Location: feature-pics.php'); }else{ echo "Error: ".mysqli_error($con); } } ?> <br> <input type="submit" name="activate" id="activate" value="Activate"> <input type="submit" name="delete" id="delete" value="Delete Selected"> </form>
  2. So what i am trying to do is based on a administrative section of the website to edit pictures in a section of the website. the page displays all the images in the database, each image has 3 inputs to them, all based under one form for all pictures. so each picture has two checkboxes and one number input. First checkbox is based on if the picture will be active or not for displaying on the website. second input is the order of when this picture will be displayed ( yes this is for a feature banner that changes images based on time ). the last input is the second checkbox for deleting the photo(this checkbox is working fine as it uses a different submit button). I have this page set up so it will have all the active pictures already checked. now when trying to "uncheck" the active picture, it will not change the status of active. I will provide the code for the whole thing, maybe im going about this the wrong way. just mainly need some direction on how to go about what im trying to accomplish. my database layout: NAME: feature | id | position | pic | active | ======================== | 1 | 3 | jpg | true | | 2 | 1 | jpg | true | | 3 | NULL | jpg | false | | 4 | 2 | jpg | true | <form method="post" id="delete" name="delete"> <?php $pic_query = mysqli_query($con, "SELECT * FROM feature") or die("Pic_Query Failed: ".mysqli_error($con)); $count = mysqli_num_rows($pic_query); while($row = mysqli_fetch_array($pic_query)){ extract($row); if($active=='true'){ $checked = 'checked'; }else{ $checked = NULL; } ?> <div style="display:inline-block; margin: 4px; padding:5px; border:solid 1px #000000; border-radius:5px;"> <img src="../images/feature/<?php echo $pic ?>" width="200px"> <br>Active: <input type="checkbox" id="active[<?php echo $id ?>]" name="active[]" value="true" <?php echo $checked ?>> <br>Position: <input type="number" id="pos[<?php echo $id ?>]" name="pos[]" min="1" max="5" value="<?php echo $position; ?>"> <br>Delete: <input type="checkbox" id="checkbox[<?php echo $id; ?>]" name="checkbox[]" value="<?php echo $id; ?>"> </div> <?php } if(isset($_POST['delete'])){ for($i=0;$i<count($_POST['checkbox']);$i++){ $checkbox = $_POST['checkbox']; $del_id = $checkbox[$i]; $byebye = mysqli_query($con, "SELECT * FROM feature WHERE id='$del_id'") or die("File Delete Error: ".mysqli_error($con)); while($rows = mysqli_fetch_array($byebye)){ extract($rows); unlink("../images/features/".$pic); } $sql = "DELETE FROM pictures WHERE id='$del_id'"; $result = mysqli_query($con, $sql) or die("Delete Error: ".mysqli_error($con)); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=feature-pics.php\">"; } } mysqli_close(); if(isset($_POST['activate'])){ for($n=0;$n<count($_POST['active']);$n++){ $live = $_POST['active'][$n]; $pos = $_POST['pos'][$n]; $act_id = $active[$n]; $update = "UPDATE feature SET position='$pos', active='$live' WHERE id='$act_id'"; $result = mysqli_query($con, $update) or die("Active Error: ".mysqli_error($con)); echo "<br>".$live; //Testing whats being sent echo "<br>".$pos; //Testing whats being sent } // if successful redirect to delete_multiple.php if($result){ echo "" //meta refresh here, took out for testing } } mysqli_close(); ?> <br> <input type="submit" name="activate" id="activate" value="Activate"> <input type="submit" name="delete" id="delete" value="Delete Selected"> </form>
  3. not sure if this has ever happen with anyone and not sure if its a problem with php or whatever, but basically what is happening is with a couple images I am testing with will not upload. Other images will upload fine, when I ran into this problem I even tried with files with the same aspect ratio and close to same file size and they work fine. I have tried uploading the same image that fails with two completely different scripts and still fails. tried changing the name of the pic, made a copy of the pic, opened it up in my photo editing software and re-save the image( kept it same image size but it ended up making the file size larger ) and all failed. my first image upload script showed me warnings: the Directory "DOES" exist, due to other photos have been uploaded. here is the script to the one that shows me the warning messages: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Image Upload</title> <script src="js/editor.js" type="text/javascript"></script> </head> <body> <?php $query = 'SELECT * FROM news'; if ($stmt = mysqli_prepare($con, $query)) { /* execute query */ mysqli_stmt_execute($stmt); /* store result */ mysqli_stmt_store_result($stmt); } switch($_POST['uploaded']) { case 'true': if(isset($_FILES['files'])){ $errors= array(); foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){ $file_name = strtolower($_FILES['files']['name'][$key]); $file_size =$_FILES['files']['size'][$key]; $file_tmp =$_FILES['files']['tmp_name'][$key]; $file_type=$_FILES['files']['type'][$key]; if($file_size > 6291456){ $errors[]='File size must be less than 4 MB'; } $desired_dir="files"; if(empty($errors)==true){ if(is_dir($desired_dir)==false){ mkdir("$desired_dir", 0700); // Create directory if it does not exist mkdir("$desired_dir/thumb", 0700); } if(is_dir("$desired_dir/".$file_name)==false){ move_uploaded_file($file_tmp,"files/".$file_name); $width = 268; $height = 200; list($width_orig, $height_orig) = getimagesize("files/".$file_name); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg("files/".$file_name); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagejpeg($image_p, "files/thumb/".$file_name, 100); $filename = $file_name; }else{ //rename the file if another one exist $new_dir=$file_name.time(); rename($file_tmp,"files/".$new_dir); $filename = $new_dir; } ?> Upload Finished: <?php echo $filename ?> <button onClick="findwrap('<?php echo $filename; ?>'); return false;">Close</button> <?php }else{ print_r($errors); } } } break; default: ?> - Select a photo to upload.<br> - Wait for it to finish upload and click the "Close" button<br> - Not the "x" or it won't work!! <form action="" method="POST" enctype="multipart/form-data"> <input type="file" name="files[]" /><br /> <input hidden="true" name="uploaded" type="hidden" value="true"> <input type="submit" /> </form> <?php } ?> </body> </html> the other script i used was one that I found online: https://app.box.com/shared/bbkbdsmz7b they both work with other images, just not this one. I just don't want to have this happen with my client. here is the pic I am trying to upload as a test pic( to large to upload to form ), and yes its a picture of my cat... lol : https://www.dropbox.com/s/i5s2hbi21mqodnn/iPhone%20Pictures%20009.JPG
  4. Just for everyone to see how I fixed my issue. it was due to jquery. this section <script> $("#submit").click(function() { $("#hiddenpost").val($("#admin_post").html()); }); </script> i had to add a .replace after the .html so it looks like this and solved my issue <script> $("#submit").click(function() { $("#hiddenpost").val($("#admin_post").html().replace(/<div>/gi,'').replace(/<\/div>/gi,'<br>')); }); </script> yes I went back to using .html(), the .text() was being difficult to work with and the above script solved my problem Thanks to all who have helped me out, got me pointed in the right direction. thank you
  5. okay, for the time being i am going to mark this topic as solved, due to this is no longer a "PHP" problem and after I do some more research I will make new post in the javascript section If i can't figure anything out
  6. that does not do anything as the jquery .text() eliminates any new lines. ive already tried. it would have to be in jquery to get my linebreaks back
  7. yeah, i know the bbcode tags work, just the new lines dont. is there some kind of work around that could be done for this? ps. i am very greatful for your help on this. i feel like i owe you something
  8. please provide php code for further help, other wise its just a shot in the dark to help
  9. i see... so when using .text() if my content looks like this it will display like this now for my rich text editor, it kinda defeats the purpose of being a "rich text editor" if you need to add html into the content before submitting.
  10. guess i was wrong for the easy part haha, im assuming when the content from the div when sent to the teaxtarea for submit, the .text() clears all html and keeps it as plain text right?
  11. yes i saw your post, i changed the .html() to .text() and yes it got rid of the magical divs... awesome... its a step forward now and not backwards haha... now just to do some tweaking so it will keep new lines with <br> which should be simple enough
  12. it is in the $_POST data, which is sent to the mysql db and shows the <div>'s in the database. using textarea instead of <div editable="true"> seems to not have the magical divs when submited but then my custom bbcode buttons dont send to the textarea... im going to do some more research on sending content from div to hidden textarea without jquery and see if it is jquery that is messing my code up. ive downloaded jquery 1.10.2 uncompressed to see if there was some stuff in there that is creating divs... which there seems to be a few in there about it. but im not the best with jquery thats why i dont use it to often.
  13. I actually removed my preg_replace for the bbcode and it still gives me these magical divs haha, now to look farther in what the heck is happening.. grrr lol, well I was just hoping it was just a minor thing i missed, but apperently its not. how could this be debugged when its working, just adding divs on every new line... like it will wrap a <br> in a div haha
×
×
  • 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.