Jump to content

unplugged_web

Members
  • Posts

    897
  • Joined

  • Last visited

Posts posted by unplugged_web

  1. I wonder if somebody can help me please, I've got this code, but it keeps telling me there's an error telling me that mysql_fetch_array(): supplied argument is not a valid MySQL:

     <?php$con = mysql_connect($host,$username,$password);if (!$con)  {  die('Could not connect: ' . mysql_error());  } mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM portfoliosWHERE artist_id = $idORDER BY order ASC");while($row = mysql_fetch_array($result)){echo $row['name'] . " Portfolio <a href=\"new_site/admin/edit_portfolio.php?artist=$id&portfolio=". $row['id'] . "\" class=\"button\"><img src=\"/new_site/admin/images/edit.png\" title=\"Edit\" /></a> <a href=\"new_site/admin/delete_portfolio.php?artist=$id&portfolio=". $row['id'] . "\" class=\"button\"><img src=\"/new_site/admin/images/delete.png\" title=\"Delete\" /></a> <a href=\"new_site/admin/portfolio_order.php?direction=1&artist=$id&portfolio=". $row['id'] . "\" class=\"button\"><img src=\"/new_site/admin/images/up.png\" title=\"Up\" /></a> <a href=\"new_site/admin/portfolio_order.php?direction=-1&artist=$id&portfolio=". $row['id'] . "\" class=\"button\"><img src=\"/new_site/admin/images/down.png\" title=\"Down\" /></a> <a href=\"new_site/admin/add_to_portfolio.php?artist=$id&portfolio=". $row['id'] . "\" class=\"button\">Add image</a><br />";}mysql_close($con);?>

    I've had a look at this page but that gives the impress what I've got is correct

  2. You're trying to work on the temp file after moving it. Moving does exactly what it says, it moves the file. That means it isn't in the place it was moved from after it is moved, it is in the destination. Moving is not copying, it does not create a copy of the file. So you're resizing the file, then moving it, then trying to resize the original file again but it's not there any more because you just moved it. That's why he suggested creating another copy of the temp file first, then resizing and moving each temp file to the appropriate destination.
    That's what I thought I was doing, I thought the last bit
    if(move_uploaded_file($temp_name, $target))

    was what was moving it?

  3. I'm sorry I just don't get it, I tried to follow what you said, but just got a whole heap of errors:

    Warning: getimagesize(/tmp/php7FVaT0) [function.getimagesize]: failed to open stream: No such file or directory in /new_site/admin/portfolio_image_added.php on line 14 Warning: Division by zero in /new_site/admin/portfolio_image_added.php on line 16 Warning: imagecreatefromjpeg(/tmp/php7FVaT0) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in //new_site/admin/portfolio_image_added.php on line 20 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /new_site/admin/portfolio_image_added.php on line 33 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /new_site/admin/portfolio_image_added.php on line 34 Warning: imagejpeg(): supplied argument is not a valid Image resource in /new_site/admin/portfolio_image_added.php on line 38 Warning: imagedestroy(): supplied argument is not a valid Image resource in /new_site/admin/portfolio_image_added.php on line 53
    I've changed the code to this:
    // resizes an image to fit a given width in pixels.// works with BMP, PNG, JPEG, and GIF// $file is overwrittenfunction fit_image_file_to_width($file, $w, $mime = 'image/jpeg') {    list($width, $height) = getimagesize($file);    $newwidth = $w;    $newheight = $w * $height / $width;     switch ($mime) {        case 'image/jpeg':            $src = imagecreatefromjpeg($file);            break;        case 'image/png';            $src = imagecreatefrompng($file);            break;        case 'image/bmp';            $src = imagecreatefromwbmp($file);            break;        case 'image/gif';            $src = imagecreatefromgif($file);            break;    }     $dst = imagecreatetruecolor($newwidth, $newheight);    imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);     switch ($mime) {        case 'image/jpeg':            imagejpeg($dst, $file);            break;        case 'image/png';            imagealphablending($dst, false);            imagesavealpha($dst, true);            imagepng($dst, $file);            break;        case 'image/bmp';            imagewbmp($dst, $file);            break;        case 'image/gif';            imagegif($dst, $file);            break;    }     imagedestroy($dst);} // init file vars$pic  = $_FILES['photo']['name'];$target = '/uploads/image/filename/' . basename( $_FILES['photo']['name']);$temp_name = $_FILES['photo']['tmp_name'];$type = $_FILES["photo"]["type"]; // Connects to your Database  mysql_connect($host,$username,$password) or die(mysql_error()) ;  mysql_select_db($database) or die(mysql_error()) ; // get form data$class = $_POST['class'];$foreign_id = $_POST['foreign_id'];$name = mysql_real_escape_string(isset($_POST['name']) ? $_POST['name'] : 'No name');$order = $_POST['order']; //Writes the information to the database mysql_query("INSERT INTO `images` (`id`, `class`, `foreign_id`, `title`, `filename`, `created`, `modified`, `order`, `category`) VALUES (NULL, '$_POST[class]', '$_POST[foreign_id]', '$_POST[name]', '$pic', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '$_POST[order]', '$style')");  // resize the image in the tmp directorysfit_image_file_to_width($temp_name, 700, $type); //Writes the photo to the serverif(move_uploaded_file($temp_name, $target))$pic2  = $_FILES['photo']['name'];$target2 = '/uploads/image/filename/thumb/thumbnailbig/' . basename( $_FILES['photo']['name']);$temp_name2 = $_FILES['photo']['tmp_name'];$type2 = $_FILES["photo"]["type"];fit_image_file_to_width($temp_name2, 100, $type2);if(move_uploaded_file($temp_name2, $target2))

  4. did you read about copy()? what specific questions do you have or what don't you understand? Do you understand that from the tmp folder you moved the image to another folder, right?Well now, if you want to move the image to another folder, but still want to keep it in the current folder.. you would have to make a copy of it. Just think of it like making copies of files on your computer with an OS. copy, paste, etc.
    I understand what you're saying, but I don't just want to make a copy of the image I want to resize it as well so that it's only 100 pixels wide instead of 700. Would this work:
    $style = (isset($_POST['style']) ? implode(' ', $_POST['style']) : '');//create array to temporarily grab variables$input_arr = array();//grabs the $_POST variables and adds slashesforeach ($_POST as $key => $input_arr) {    $_POST[$key] = addslashes($input_arr);} // resizes an image to fit a given width in pixels.// works with BMP, PNG, JPEG, and GIF// $file is overwrittenfunction fit_image_file_to_width($file, $w, $mime = 'image/jpeg') {    list($width, $height) = getimagesize($file);    $newwidth = $w;    $newheight = $w * $height / $width;     switch ($mime) {        case 'image/jpeg':            $src = imagecreatefromjpeg($file);            break;        case 'image/png';            $src = imagecreatefrompng($file);            break;        case 'image/bmp';            $src = imagecreatefromwbmp($file);            break;        case 'image/gif';            $src = imagecreatefromgif($file);            break;    }     $dst = imagecreatetruecolor($newwidth, $newheight);    imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);     switch ($mime) {        case 'image/jpeg':            imagejpeg($dst, $file);            break;        case 'image/png';            imagealphablending($dst, false);            imagesavealpha($dst, true);            imagepng($dst, $file);            break;        case 'image/bmp';            imagewbmp($dst, $file);            break;        case 'image/gif';            imagegif($dst, $file);            break;    }     imagedestroy($dst);} // init file vars$pic  = $_FILES['photo']['name'];$target = '/uploads/image/filename/' . basename( $_FILES['photo']['name']);$temp_name = $_FILES['photo']['tmp_name'];$type = $_FILES["photo"]["type"];$pic2  = $_FILES['photo']['name'];$target2 = '/uploads/image/filename/thumbnailbig/' . basename( $_FILES['photo']['name']);$temp_name2 = $_FILES['photo']['tmp_name'];$type2 = $_FILES["photo"]["type"]; // Connects to your Database  mysql_connect($host,$username,$password) or die(mysql_error()) ;  mysql_select_db($database) or die(mysql_error()) ; // get form data$class = $_POST['class'];$foreign_id = $_POST['foreign_id'];$name = mysql_real_escape_string(isset($_POST['name']) ? $_POST['name'] : 'No name');$order = $_POST['order']; //Writes the information to the database mysql_query("INSERT INTO `images` (`id`, `class`, `foreign_id`, `title`, `filename`, `created`, `modified`, `order`, `category`) VALUES (NULL, '$_POST[class]', '$_POST[foreign_id]', '$_POST[name]', '$pic', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '$_POST[order]', '$style')");  // resize the image in the tmp directorysfit_image_file_to_width($temp_name, 700, $type);fit_image_file_to_width($temp_name2, 100, $type2); //Writes the photo to the serverif(move_uploaded_file($temp_name, $target))if(copy($temp_name2, $target2))

    or am I thinking about it in the wrong way?

  5. once you use move_upload_file() to move temporary file to a destination the uploaded file has been moved to its destination. you can copy() the file from moved desstination to a thumbnail folder.
    How do I do that, sorry I'm very new to uploading images - this is the first time I've tried to do it
  6. I'm uploading an image, but I want it to go to two different folders, one folder the image will be the regular size which is 700 pixels wide and the other folder will just be a thumbnail. I can get it to add the image to the database as well as upload it to the first folder, but I can't get it to upload to the thumbnail folder too. This is what I've got, but I'm site sure where it's going wrong:

    $style = (isset($_POST['style']) ? implode(' ', $_POST['style']) : '');//create array to temporarily grab variables$input_arr = array();//grabs the $_POST variables and adds slashesforeach ($_POST as $key => $input_arr) {    $_POST[$key] = addslashes($input_arr);} // resizes an image to fit a given width in pixels.// works with BMP, PNG, JPEG, and GIF// $file is overwrittenfunction fit_image_file_to_width($file, $w, $mime = 'image/jpeg') {    list($width, $height) = getimagesize($file);    $newwidth = $w;    $newheight = $w * $height / $width;     switch ($mime) {        case 'image/jpeg':            $src = imagecreatefromjpeg($file);            break;        case 'image/png';            $src = imagecreatefrompng($file);            break;        case 'image/bmp';            $src = imagecreatefromwbmp($file);            break;        case 'image/gif';            $src = imagecreatefromgif($file);            break;    }     $dst = imagecreatetruecolor($newwidth, $newheight);    imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);     switch ($mime) {        case 'image/jpeg':            imagejpeg($dst, $file);            break;        case 'image/png';            imagealphablending($dst, false);            imagesavealpha($dst, true);            imagepng($dst, $file);            break;        case 'image/bmp';            imagewbmp($dst, $file);            break;        case 'image/gif';            imagegif($dst, $file);            break;    }     imagedestroy($dst);} // init file vars$pic  = $_FILES['photo']['name'];$target = '/uploads/image/filename/' . basename( $_FILES['photo']['name']);$temp_name = $_FILES['photo']['tmp_name'];$type = $_FILES["photo"]["type"];$pic2  = $_FILES['photo']['name'];$target2 = '/uploads/image/filename/thumbnailbig/' . basename( $_FILES['photo']['name']);$temp_name2 = $_FILES['photo']['tmp_name'];$type2 = $_FILES["photo"]["type"]; // Connects to your Database  mysql_connect($host,$username,$password) or die(mysql_error()) ;  mysql_select_db($database) or die(mysql_error()) ; // get form data$class = $_POST['class'];$foreign_id = $_POST['foreign_id'];$name = mysql_real_escape_string(isset($_POST['name']) ? $_POST['name'] : 'No name');$order = $_POST['order']; //Writes the information to the database mysql_query("INSERT INTO `images` (`id`, `class`, `foreign_id`, `title`, `filename`, `created`, `modified`, `order`, `category`) VALUES (NULL, '$_POST[class]', '$_POST[foreign_id]', '$_POST[name]', '$pic', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '$_POST[order]', '$style')");  // resize the image in the tmp directorysfit_image_file_to_width($temp_name, 700, $type);fit_image_file_to_width($temp_name2, 100, $type2); //Writes the photo to the serverif(move_uploaded_file($temp_name, $target))if(move_uploaded_file($temp_name2, $target2))

  7. That's I didn't notice that - I guess I was looking in the wrong place. In phpmyadmin it said that there was an error, but in a php checker it said there wasn't any errors at all so I got quite confused. Thanks

  8. Please help me, I've no idea what's going wrong here. I'm trying to add to a database. This works:

    mysql_query("INSERT INTO `images` (`id`, `class`, `foreign_id`, `title`, `filename`, `created`, `modified`, `order`, `category`) VALUES (NULL,'Bio','99','test','image.jpg',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,'0','0')"); 

    But this doesn't:

    mysql_query("INSERT INTO `images` (`id`, `class`, `foreign_id`, `title`, `filename`, `created`, `modified`, `order`, `category`) VALUES (NULL, '$_POST[class]'', '$_POST[foreign_id]', '$_POST[name]', '$_POST[pic]', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '$_POST[order]', '$_POST[category]')"); 

    All of the fields have the correct values, but for some reason it just won't let me do it. I've sent three days trying to get it sorted, but I think I'm just going round in circles now.

  9. i think it's currently getting evaluated as
    UPDATE images SET title = ('$title' AND category = '$style') WHERE id = '$image_id'

    try using a comma instead of AND to update multiple cells.

    Brilliant thank you, that's now working.
  10. Do you know what your query looks like before it gets executed? have you tried the same query via command line or phpMyAdmin?
    If I try adding is directly using phpmyadmin (just replacing $title, $style and $image_id with the actual values) then exactly the same thing happens. Only title updates but no matter what I add it only changes to '0'
  11. I now seem to be having a problem adding the results into a database. I'm not sure why but it's just not updating :( This is what I've got:

    <?php$style = (isset($_POST['style']) ? implode(' ', $_POST['style']) : '');$title = $_POST['Title'];$image_id = $_POST['image_id']; echo $style;echo "<br />";echo $title;echo "<br />";echo $image_id; include 'includes/db.php';$con = mysql_connect($host,$username,$password);if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db($database, $con);mysql_query("UPDATE images SET title = '$title' AND category = '$style' WHERE id = '$image_id'");mysql_close($con);?>

    Everything seems to be outputting correctly, style, title and image_id all have values. Title changes to '0' regardless of what it actually is but nothing else changes at all.

  12. Thank you, I've changed it to:

     <?php$con = mysql_connect($host,$username,$password);if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM styles");while($row = mysql_fetch_array($result)){echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";$style_id = $row['id'];if (in_array($style_id,$new_category)){echo "checked=\"checked\"";}else{echo "checked=\"unchecked\"";}echo "/>";}mysql_close($con);?>

    and it now works perfectly :)

  13. while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";

    That is your entire while loop. There aren't any brackets to tell it how many lines to loop over, so it loops over 1 line. It loops over that line outputting the unclosed checkboxes, and then runs the rest of the code once after the loop finishes. It sounds like you need more lines then just that one in the loop.

    I thought the whole loop was this:
    while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";$style_id = $row['id'];if (in_array($style_id,$new_category)){echo "checked=\"checked\"";}else{echo "checked=\"unchecked\"";}echo "/>";

    That's what I wanted/tried to get it to be

  14. The checkbox tags aren't closed.
    The only way I can get them to close it so add "/>' before the in_array - even if that's not there they still won't close. I know it probably sounds quite straightforward but I can't work it out - I don't know where I'm going wrong :(
  15. i did ask for the generated HTML, can you provide that? You should be looking at what is being produced to see why it might not be showing correctly. If you aren't generating proper HTML, then you can't trust your logic. Also, since you didn't include the debugging lines, I'm not sure how you debugged $new_category. try var_dump instead. It sounds like the values are right, or at least there, but it sounds like you aren't putting the HTML together correctly.
    This is what being generated. It doesn't look like it's generating anything after the first line, but I don't understand why.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>Untitled Document</title></head><body><div><form action="" method="get" name="Update_Image"><img src="/uploads/image/filename/01-0.jpg" alt="" title="" /><br />Image title: <input name="Title" value=""/><br />Image class: <input name="class" value=""/><br />architecture: <input name="3" type="checkbox" <br />black & white: <input name="5" type="checkbox" <br />cut paper: <input name="6" type="checkbox" <br />vector: <input name="8" type="checkbox" <br />food & beverage: <input name="11" type="checkbox" <br />healthcare: <input name="12" type="checkbox" <br />humerous: <input name="13" type="checkbox" <br />infographics: <input name="15" type="checkbox" <br />tweens: <input name="48" type="checkbox" <br />nature: <input name="17" type="checkbox" <br />logo & lettering: <input name="18" type="checkbox" <br />maps: <input name="19" type="checkbox" <br />oil/acrylic: <input name="20" type="checkbox" <br />animation: <input name="44" type="checkbox" <br />pin ups: <input name="24" type="checkbox" <br />portraits: <input name="61" type="checkbox" <br />retro: <input name="26" type="checkbox" <br />watercolor: <input name="29" type="checkbox" <br />painterly: <input name="32" type="checkbox" <br />photo realistic: <input name="37" type="checkbox" <br />digital: <input name="47" type="checkbox" <br />CGI: <input name="45" type="checkbox" <br />collage: <input name="41" type="checkbox" checked="unchecked"/><br />category: 3 5 6 8 11 12 13 15 48 17 18 19 20 44 24 61 26 29 32 37 47 45 41<br />new: Array<br />id: </form></div></body></html>

  16. what does your generated HTML output look like? Have you checked the values of anything in your script? $category, $style_id, etc? I don't see any attempts at debugging.
    I've changed the page and the category outputs correctly. If I move the $style_id = $row['id']; row to just under the while($row = mysql_fetch_array...... then style_id out puts correctly, but the checkboxes don't show at all. If I leave it where it is then the checkboxes how but they're not checked as they should be. New_category just outputs Array whatever I do :( This is the code I've got so far:
    <?php$image = intval($_GET['id']);include 'includes/db.php';$con = mysql_connect($host,$username,$password);if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM images WHERE id = $image");($row = mysql_fetch_array($result));mysql_close($con);$filename = $row['filename'];$title = $row['title'];$class = $row['class'];$category = $row['category'];$new_category =  (explode(" ",$category));?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>Untitled Document</title></head><body><div><form action="" method="get" name="Update_Image"><img src="/uploads/image/filename/<?php echo $filename ?>" alt="<?php echo $title ?>" title="<?php echo $title ?>" /><br />Image title: <input name="Title" value="<?php echo $title ?>"/><br />Image class (Portfolio, Artist or Bio): <input name="class" value="<?php echo $class ?>"/><?php$con = mysql_connect($host,$username,$password);if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM styles");while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";$style_id = $row['id'];if (in_array($style_id,$new_category)){echo "checked=\"checked\"";}else{echo "checked=\"unchecked\"";}echo "/>";mysql_close($con);?></form></div></body></html>

  17. Maybe it's your browser's cache. Though maybe it's server-side cacheing. I've only ever experienced server-side cacheing with SWF files, though.
    It's now working and the page is loading, although the original problem is still there. It's still not ticking only the boxes that are in the 'category' field:
     <?php$con = mysql_connect($host,$username,$password);if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM styles");while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";$style_id = $row['id'];$category = $row['category'];$new_category =  (explode(" ",$category));if (in_array($style_id,$new_category)){echo "checked=\"checked\"";}else{echo "checked=\"unchecked\"";}echo "/>";mysql_close($con);?>

  18. I just tried your new file but it's not giving me that error message. It's working fine for me. What error message do you see?
    Still exactly the same one:Parse error: syntax error, unexpected '{' in /new_site/edit.php on line 6 EDIT:I think there might be a problem on the server - I've deleted the file from the server but when I go to the same address I still get the error rather than being told the page doesn't exist! The hosting has just been moved to a new server coudl that be causing a problem?
  19. I'm pretty sure I've removed all of the spaces, but I'm still getting the same error. I've attached the file with the spaces gone. Yes I did copy the code from somewhere but I ended up getting myself in such a muddle I don't know where I got it from.

    edit.php

  20. I copied your code and I'm not getting the error message you mentioned. And that error message shouldn't be there.
    This is the page where the code is: here I've got other pages on that site that are working okay - it's just that one. The hosts said that they've just moved it to a new server and I did wonder if that was the problem but I'm still getting hte error
  21. What do the first few lines of your code look like now?
    Thats now:
     <?php include 'includes/db.php'; $con = mysql_connect($host,$username,$password);if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM images WHERE id = $image");($row = mysql_fetch_array($result));mysql_close($con);$filename = $row['filename'];$title = $row['title'];$class = $row['class'];$category = $row['category'];$image = intval($_GET['id']);?>

  22. Get rid of the extra <?php ?> blocks and then see where the error is.Something before line 8 is causing the problem.
    I removed everything above line 8 that wasn't needed to connect but the same error was there - just changed the line number :(
×
×
  • Create New...