justAnoob Posted March 30, 2009 Share Posted March 30, 2009 I'm still stuck on saving the image paths to mysql and then calling the images to dispaly on the page. I looked everywhere,,, google, yahoo, daniweb.... Can't find anything that will really help. Quote Link to comment https://forums.phpfreaks.com/topic/151845-need-help-to-finish-my-site/ Share on other sites More sharing options...
Brian W Posted March 30, 2009 Share Posted March 30, 2009 you'll be using a INSERT query to add the images to a table, you'll useĀ a SELECT query to grab the image paths from the table, and you'll do some looping to output them. Help? I'm sure not because I'm as vague as your question. Quote Link to comment https://forums.phpfreaks.com/topic/151845-need-help-to-finish-my-site/#findComment-797355 Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 I'm still stuck on saving the image paths to mysql and then calling the images to dispaly on the page. I looked everywhere,,, google, yahoo, daniweb.... Can't find anything that will really help. Ā What exactly are you stuck on? Quote Link to comment https://forums.phpfreaks.com/topic/151845-need-help-to-finish-my-site/#findComment-797356 Share on other sites More sharing options...
justAnoob Posted March 30, 2009 Author Share Posted March 30, 2009 I have images on my server in the folder "userimages". I have several sub foloders off of that (computers, students, and so on). Uploading the picture to the server is no problem. Displaying the pictures from the server is easy also... But right now I'm calling them straight from the server. What I want to do is when a picture is uploaded, the picture goes to the server(done), and then the info goes to mysql(done except for image path). The reason I want to do this is because it seems easier to call everything from mysql so it can display inside a neat table on my page. Understand what I'm saying. Here is the upload so far. <?php session_start(); $host = "0000000000"; $username = "0000"; $password = "00000000"; $db_name = "0000000000"; $tbl_name1 = "00000"; $tbl_name2 = "000000000000"; mysql_connect("$host", "$username", "$password") or die("Could not connect."); mysql_select_db("$db_name") or die("Could not find database"); $item_name = mysql_real_escape_string($_POST['item_name']); $description = mysql_real_escape_string($_POST['description']); $in_return = mysql_real_escape_string($_POST['in_return']); $imgpath = ???????? define ("MAX_SIZE","1000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if(isset($_POST['Submit'])) { $image=$_FILES['image']['name']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "gif") && ($extension != "png")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } $category = $_POST['listmenu']; $image_name=time().'.'.$extension; $newname="userimages/$category/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; } } } } $findit = $_SESSION['id']; $result=mysql_query("SELECT id FROM members WHERE username = '$findit'"); $row=mysql_fetch_assoc($result); $user_id = $row['id']; $sql = "INSERT INTO member_trades(item_name, description, in_return, user_id)VALUES('$item_name','$description','$in_return', '$user_id')"; mysql_query($sql) or die(mysql_error()); if(isset($_POST['Submit']) && !$errors) { header ("http://www.0000000000.com/previewsave.php"); echo "<h1>Image Uploaded Successfully!</h1>"; echo '<img src="' . $newname . '" width="150" border="0"><br />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/151845-need-help-to-finish-my-site/#findComment-797363 Share on other sites More sharing options...
Brian W Posted March 30, 2009 Share Posted March 30, 2009 the variable $newname seems to be what you'll want to save as the path. Quote Link to comment https://forums.phpfreaks.com/topic/151845-need-help-to-finish-my-site/#findComment-797370 Share on other sites More sharing options...
justAnoob Posted March 30, 2009 Author Share Posted March 30, 2009 Ok,, so then if I save $newname as $imgpath.. and the path is put into mysql.. How would I go about displaying the image using the imgae path from mysql.. Sorry for all the questions.. I've looked just about everywhere I could for some answers. Quote Link to comment https://forums.phpfreaks.com/topic/151845-need-help-to-finish-my-site/#findComment-797373 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.