Jump to content

unplugged_web

Members
  • Posts

    897
  • Joined

  • Last visited

Everything 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. I'm sorry I really don't understand where or how to cop it. I didn't write the original code myself and I don't know what bit does what.
  3. That's what I thought I was doing, I thought the last bitif(move_uploaded_file($temp_name, $target)) was what was moving it?
  4. I'm sorry I just don't get it, I tried to follow what you said, but just got a whole heap of errors: 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))
  5. 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?
  6. How do I do that, sorry I'm very new to uploading images - this is the first time I've tried to do it
  7. 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))
  8. 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
  9. 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.
  10. Brilliant thank you, that's now working.
  11. 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'
  12. 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.
  13. 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
  14. So how do I tell it to continually loop until it's done?
  15. 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
  16. 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
  17. 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>
  18. 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>
  19. 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);?>
  20. 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?
  21. 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
  22. I've also made the 'includes' part of the code a full address so you should be able to connect to the database. Thanks for trying to help me get this sorted edit.php
  23. 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
  24. 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']);?>
  25. 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...