Jump to content

steve490

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

steve490's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey guys, I have a gallery of photos and im using the 'GET' method to view each large picture, I created a comment box to use with each picture but when a user posts a comment the image disappears but it shows the comment. The comment is inserted into the database but without the image ID so when I go to view the image it shows an empty box. Also when ever the page is refreshed or viewed an empty comment is inserted... hope its clear, heres all the code:- $dbname = '***'; mysql_select_db($dbname); if (isset ($_GET['id'])) { $imgid = $_GET['id']; } $image_viewer = "SELECT * FROM img WHERE imgid='$imgid'"; $show_image = mysql_query($image_viewer); mysql_close($conn); $email = $_SESSION['email']; $thread = $_POST{"thread"}; $date = date("H:i jS F Y"); $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname2 = '****'; mysql_select_db($dbname2); $comment_saver = "INSERT INTO threads (imageid, email, thread, timestamp) VALUES ('".$imgid."','".$email."','".$thread."','".$date."')"; $comment = mysql_query($comment_saver); $sql = "SELECT * FROM threads WHERE imageid='$imgid'"; $result = mysql_query($sql) or die(mysql_error()); The html <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <legend>Comment Box</legend><p> Have a thought... write it here:<br><textarea cols="60" rows="5" name="thread"></textarea><br> <input type="submit" value="Post Comment"> </form> <?php while ($row = mysql_fetch_array($result)) { echo "Posted by: " .$email. "<br /> "; echo " On " . $date . "<br /> "; echo "Comment: " . $thread . "\n" . "<br /> "."<br /> "; }?> </div> Cheers... need any more info let me know
  2. Hey guys, Heres the problem... Im trying to upload an image with my uploader (this works fine) but im having problems with the GD library trying to create thumbnails but I've never used the library before so having problems getting an output. I've tried echoing the GD code to find the problem but i get nothing returned. Can someone explain what i've done wrong and how to resolve the issue. All the folders and directories are in the right place and the images are being uploaded into the 'uploads' folder but not the 'thumbs' folder. Heres all the code:- $pic=($_FILES['name']); $imagefolder='/'; $thumbsfolder='/'; $pics=directory($imagefolder,"jpg,JPG,JPEG,jpeg,png,PNG"); $pics=ditchtn($pics,"tn_"); $files = directory("/","jpg,gif"); $name='/uploads'; //Original filename $filename='/thumbs'; //Filename of the resized image $new_w = '100'; $new_h = '100'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = '****'; mysql_select_db($dbname); $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $pic = ($_FILES['uploadedfile']['name']); mysql_query ("INSERT INTO img (name, email) VALUES ('uploads/$pic','$_SESSION[email]')"); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded to" . $target_path; } else{ echo "There was an error uploading the file, please try again!"; } if ($pics[0]!="") { foreach ($pics as $p) { createthumb($p,"tn_".$p,150,150); } } /* Function ditchtn($arr,$thumbname) filters out thumbnails */ function ditchtn($arr,$thumbname) { foreach ($arr as $item) { if (!preg_match("/^".$thumbname."/",$item)){$tmparr[]=$item;} } return $tmparr; } function createthumb($name,$filename,$new_w,$new_h) { $system=explode(".",$name); if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);} if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);} $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); if (preg_match("/png/",$system[1])) { imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); } function directory($dir,$filters) { $handle=opendir($dir); $files=array(); if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}} if ($filters != "all") { $filters=explode(",",$filters); while (($file = readdir($handle))!==false) { for ($f=0;$f<sizeof($filters);$f++): $system=explode(".",$file); if ($system[1] == $filters[$f]){$files[] = $file;} endfor; } } closedir($handle); return $files; } Im a novice with php so im still trying to understand how most things work and get rid of the silly mistakes I keep making. Thanks for the help
  3. Can anyone tell me the best way to create thumbnails (GD library)? or is there something else? I have a simple upload script (which just uploads images to a server and database) I cant find any good tutorials, I want to add code to my upload script instead of having to start again. Cheers for the help
  4. cheers guys worked like a charm After about 10 different uploads lol, I found that I cant upload any images that have a space in there name (which some pictures have). Is there anyway round this problem?
  5. Hey there, When I try and display pictures on my website from the server and database they seem to appear as the same image even though the file names are displaying different, so img2 will display the same image as img1. Here's my upload and the method im using to call the pictures from the database and server:- $conn2 = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = '****'; mysql_select_db($dbname); { $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $pic = ($_FILES['uploadedfile']['name']); mysql_query ("INSERT INTO img (name, email) VALUES ('uploads/$pic','$_SESSION[email]')"); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded to" . $target_path; } else{ echo "There was an error uploading the file, please try again!"; } $image_viewer = "SELECT * FROM img WHERE email='$_SESSION[email]'"; $show_image = mysql_query($image_viewer); mysql_close($conn2) This is where im calling the pictures from the server and database while($info = mysql_fetch_array( $show_image )) { //Outputs the images echo "<img src=/uploads/$pic".$info['uploadedfile'] ."> <br>"; echo "<b>Name:</b> ".$info['name'] . "<br> "; } Also the pictures only display in Firefox cheers for the help
  6. Ok that was the problem thank you Although the pictures are displaying now, its the same picture, so img2 will display the same image as img1 (the last upload changes all other pictures to the latest one but the file names stay the same). heres my upload and the method im using to call the pictures from the database and server:- $conn2 = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = '****'; mysql_select_db($dbname); { $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $pic = ($_FILES['uploadedfile']['name']); mysql_query ("INSERT INTO img (name, email) VALUES ('uploads/$pic','$_SESSION[email]')"); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded to" . $target_path; } else{ echo "There was an error uploading the file, please try again!"; } $image_viewer = "SELECT * FROM img WHERE email='$_SESSION[email]'"; $show_image = mysql_query($image_viewer); mysql_close($conn2) This is where im calling the pictures from the server and database while($info = mysql_fetch_array( $show_image )) { //Outputs the images echo "<img src=/uploads/$pic".$info['uploadedfile'] ."> <br>"; echo "<b>Name:</b> ".$info['name'] . "<br> "; } Thanks again
  7. didn't work but... Im trying to display the images in 'profile.php' page so could the problem be in this area?
  8. Ye it took me to the file directory and listed the images, which I can click on and then it displays the images:- Index of /uploads * Parent Directory * img1.jpg * img2.jpg
  9. Thanks for the reply, Unfortunately it didn't do the trick (although the slash needed to be removed), still the same things happening
  10. Hey, Im trying to make pictures display from the server but all im getting back is a broken picture, the folder is on 755 and i've tried 777 but neither work. Also I can right click on the broken image, click on view image and I can view it in the 'index of uploads' here's the code for the query and how im calling it. $conn2 = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = '****'; mysql_select_db($dbname); $image_viewer = "SELECT * FROM table WHERE email='$_SESSION[email]'"; $show_image = mysql_query($image_viewer); im then calling it in my HTML while($info = mysql_fetch_array( $show_image )) { echo "<img src=/uploads".$info['uploadedfile'] ."> <br>"; echo "<b>Name:</b> ".$info['name'] . "<br> "; } Cheers
  11. Cheers for replying, Im very embarrassed to say that it was not the code after all but the uploads folder on the server not refreshing, which is my fault for not checking the most obvious thing first. sorry for wasting your time
  12. hello there, Can any tell me why this upload code isn't working. What its suppose to do is upload a picture to a server and its id to a database with the users session data. its uploading to the database but not the the server folder heres the code: $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = '******'; mysql_select_db($dbname); $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $pic = ($_FILES['uploadedfile']['name']); mysql_query ("INSERT INTO img (name, email) VALUES ('uploads/$pic','$_SESSION[email]')"); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded to " . $target_path; } else{ echo "There was an error uploading the file, please try again!"; } here's the html <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> cheers in advance
  13. Hey thanks for replying, Nomadrw... that didn't work it said that the user then didn't exist ym_chaitu... it puts the password into the array... doesn't it?? im not hot with php lol, also i tried encrypting the passwords on my 'sign up' page so could this be why its not recognising the password? Although when i go into my database it hasn't encrypted them, it seems to be missing the code altogether, everything else on the page works. heres the encryption code // here im encrypting the password and add slashes if needed to make it secure $_POST['password'] = md5($_POST['password']); if (!get_magic_quotes_gpc()) { $_POST['password'] = addslashes($_POST['password']); } cheers if you need to see anything else, please let me know
  14. Hey there, Im trying to make a "email and password" log-in, on my site. I enter information into a form and it goes into the database (no problem there). When I try and log into the site it recognises the email but it doesn't recognise the password heres the code:- (sorry its a bit messy and long) connect to db //checks if there is a cookie present if(isset($_COOKIE['ID_my_site'])) //if there is, it logs the user in and directes them to the profile page { $email = $_COOKIE['ID_my_site']; $password = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM table WHERE email = '$email'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($password != $info['pass']) { } else { header("Location: profile.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // this makes sure its been filled in if(!$_POST['email'] | !$_POST['password']) { die('Wrong username or password'); } // checks whats been entered against the db if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM table WHERE email = '".$_POST['email']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('The information entered does not exist, please try again or. <a href=sign_up.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['password'] = stripslashes($_POST['password']); $info['pass'] = stripslashes($info['pass']); $_POST['password'] = md5($_POST['password']); //gives an error if the password is wrong if ($_POST['password'] != $info['pass']) { die('Incorrect password, please try again.'); } else { we add a cookie ready for the next time } } }
  15. Cheers that was quick and simple will remember how to do it now problem solved
×
×
  • 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.