Jump to content

Alexhoward

Members
  • Posts

    310
  • Joined

  • Last visited

    Never

Everything posted by Alexhoward

  1. Hi Guys, i've going round in circles trying to get an image upload to SQL think i'm on the right track cant but can't get it to work can anyone help me...? <html> <head> <title>Upload Image</title> </head> <body> <form action="imageupload.php" method="POST" enctype="multipart/form-data"> Name : <input type="text" name="imageName"> <br/> Image :<input type="file" name="imageFile"> <input type="submit" value="Upload" name="func"> </form> </body> </html> <?php include ("config.php"); /* This function take the image from form variables */ function getImageFile($file){ $takeFile = fopen($file, "r"); $file = fread($takeFile, filesize($file)); fclose($takeFile); return $file; } /* We learn image type using this function Because we will let onlt gif, jpg and png images can be uploaded */ function getfileType( $name ){ $name = explode(".", $name); $name = array_reverse($name); $name = $name[0]; return $name; } $allowedImageTypes = array("gif","jpg","png","bmp","jpeg","tiff"); if(empty($_FILES['image_file']['tmp_name'])){ echo "File not uploaded"; } else { $fileType = $_FILES['image_file']['name']; if(in_array(getfileType($fileType), $allowedImageTypes)){ $fileContent = getImageFile($_FILES['imgFile']['tmp_name']); $uploadedImage = chunk_split(base64_encode($fileContent)); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $query = "INSERT INTO images_table VALUES('NULL','$imgName','$uploadedImage')"; $result = mysql_query($query); if(mysql_affected_rows() > 0){ echo "Image has been inserted succesfully"; } else { echo "Image can not be inserted check your submission"; } } else { echo "This is not a true image type"; } } ?>
  2. Hi guy, I've got this login script that works fine on my other site, but keeps saying the password is incorrect on my new one...? can anyone see where i'm going wrong? <?php ob_start(); include("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $_POST['password'] = md5($_POST['password']); $match = "select password from $table where username = '".$_POST['username']."' and password = '".$_POST['password']."';"; $qry = mysql_query($match) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows <= 0) { echo "Sorry, that password is incorrect.<br>"; echo "<a href=index.php>Try again</a>"; echo "$num_rows"; exit; } else { $username = $_POST['username']; setcookie("loggedin", "true"); setcookie("theideasden", "$username"); echo "You are now logged in!<br>"; echo "Continue to the <a href=members.php>members</a> section."; } ob_end_flush(); ?> Also if i jig it to work, the setcookie part produces errors namely "can't set header, headers already set by....!" i don't understand it works fine on the other site...? Thanks in advance
  3. Hi, Thanks for the reply I'm not sure, Using Streamline to host my webspace would it be saved into sql...?
  4. Hi guys, I'd like to have the ability for users to upload a video to my site, and for it to be displayed on the users profile. Trouble is..... i don't know where to start.... sorry Can someone please point me in the right direction? Thanks
  5. hey, thats a genius idea! cheers
  6. excellent, thanks for the replies. my only concerns with paypal is the commission they charge, but guess i can live with that... as far as privilages, i want it to be pay per post. so if i set it up it up pay once and you can post, it would mean that they coud then post as much as they like... what would be the easiest way to do this? thankyou
  7. Hi Guys, I'm stuck...again and was wondering if anyone could help me? I basically want to set up some kind of payment method. i could just use paypal, but does anyone know how to put a secure direct payment system on their website...? also, i'd like people to pay before being able to post onto my site, but am unsure of how this will work Thanks in advance!
  8. Ok, so it's better to have lots of little tables. and join them all together. Surley the only problem is that if you were editing them manually, you'd have no idea what you where looking at with just int primary keys...? bubt i understand. this would however need a full re-build :-\
  9. Hi, thanks for your reply. I can't start making other tables now, it took long enough to input all the data in to the one i've got. this has the columns company_name | cat | subcat | link | keywords and is already a few hundred rows long. searching works fine through the keywords column i assumed it would work like a sort button?
  10. Hi guys, firstly thanks for all the help i've recieved through this site, it's been invaluable to creating my site. Now it's finished however, i'd like to redisign... my question is this: At the moment i've got lots of pages with slighlty different code to pull data out of a table differently. What i'd like to do, is change the variable dynamically, so i can achieve the same results with less pages. so, say the bones of the code to pull the data was something like... SELECT * FROM 'table' $cat $subcat $sort I'd like to be able to select a category from a DHTML tree, and it will set the variables for that category e.g. - Mens Clothing so it would make to select code: SELECT * FROM 'table' WHERE cat ='fashion' and subcat ='mens' then you could press the sort by name (for example) and it would make it: SELECT * FROM 'table' WHERE cat ='fashion' and subcat ='mens' sort by 'company_name' I imagine i'd have to make everything a form, and have a giant list of IF's to make this work, but i'm still a semi noob and don't really know how to start. Thanks for your time and help in advance Alex Howard
  11. Oh, ok so the buttons a form, and it says if the buttons pushed use this variable? Thanks for all your help. should have time to look at it tonight
  12. Thanks for your help! but i really mean a button.... i don' want to double the amount of pages by having the sort as a link I'd like to do it dynamically.. is it possible, or a just a real pain for minimal gain?
  13. Hi, Thanks for replying! and this would only sort if the button was pushed....?
  14. Can anyone point me in the right direction...? Thanks!
  15. If it pulls your data into an HTML table on the page, there is a way to export this to Excel, Rather than pull it directly from your database
  16. OK.... so it's got no built in front end...?
  17. I'm a noob too so where's you're sql saved? how do you access it directly?
  18. Hi, I take it you're not using phpMyAdmin then...?
  19. Oh sorry.... That didn't really address your point did it To my limited knowledge, these are only executed via user input sections login, sign up, etc real escape stings seem to be the way to protect against it, and stipping slashes...etc so i beleive a static site to be ok....? i'm probably wrong
  20. Hello, I only just learnt about these a few weeks ago too, so i'm no expert However, I think a google search may get you quicker answers. If it's your SQL database you're worried about, which i take it it is, just google SQL injections Tons of stuff will pop up Hope this helps
  21. Hi Everyone! I'm just looking for some advice before i start messing around with any code What i'd like is some sort by buttons e.g. - Name - Rating...etc But i'm not sure how to do this... what i'd really like it to do is something like: in the code: select * from 'where_ever' sort by $button then some kind of way to say that when a button is pressed it sets the variable Is that possible? Thanks in advance
  22. nice one! sussed that on the drive home Thanks again!
  23. Hi Guys, I've modified a search script to display the results the same as my paging script It works lovely, except.... It wont go to the next page! i think it's because it either forgets the search, or wants to search again! Could someone please tell me why? example page (for reference) : www.everyonlinestore.co.uk/testpaging.php Thanks in Advance! <?php include ("banner.php") ?> <html> <body> <form name="form" action="testpaging.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form> <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } // WHERE QUERY BUILDER ///// // Split into array of keywords $kw = @explode(" ",$var); // Get number of keywords $x = (!is_array($kw))? "1" : count($kw); // Loop for each keyword adding a where query each time. For($i=0;$i<$x;$i++){ // the current keyword (made safe from mysql_injection), depending on wether the explode() worked or not. $key = ($x==1)? mysql_escape_string($var) : mysql_escape_string($kw[$i]); // Add the where item as an appended array. $where[] = "`keywords` LIKE '%$key%' OR `keywords` LIKE '%$key%'"; } // Get full where query using the array created $where = "WHERE ".implode(" OR ",$where); // --------------- END WHERE BUILDER if (!isset($_GET['start'])) { $_GET['start'] = 0; } if (!isset($_GET['p_f'])) { $_GET['p_f'] = 0; } require "config2.php"; // All database details will be included here $page_name="testpaging.php"; // If you use this code with a different page ( or file ) name then change this $start= $_GET['start']; // To take care global variable if OFF if(!($start > 0)) { // This variable is set to zero for the first page $start = 0; } $eu = ($start -0); $limit = 12; // No of records to be shown per page. $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $query2=" SELECT * FROM links $where"; $result2=mysql_query($query2); echo mysql_error(); $nume=mysql_num_rows($result2); /////// The variable nume above will store the total number of records in the table//// ////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page/////////// $query=" SELECT * FROM links $where limit $eu, $limit "; $result=mysql_query($query); echo mysql_error(); $numresults=mysql_query($query2); $numrows=mysql_num_rows($numresults); // display wht you searched for echo "<p>You searched for: "" . $var . ""</p>"; // result numbers $a = $start + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $start; echo "<p>Showing results $b to $a of $numrows</p>"; //create table echo "<link href='Images/bkgrnd.css' rel='stylesheet' type='text/css'><table width='100%' border='0'>"; // display the users in table $c = 0; while($row = mysql_fetch_array($result)) { $user2 = html_entity_decode($row['link']); if($c%3 == 0) echo "<tr>"; // If the counter has ticked 5 times, start a new row. echo "<td scope='row' height='150' width='25%' align='center' valign='middle' class='bkgrnd'>$user2</td>"; if($c%3 == 2) echo "</tr>"; // If we're drawing the 6th pic, end this row. $c++; } if($c%5 != 4) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row echo "</table>"; // end the table ////////////////////////////// End of displaying the table with records //////////////////////// ///// Variables set for advance paging/////////// $p_limit=12; // This should be more than $limit and set to a value for whick links to be breaked $p_f= $_GET['p_f']; // To take care global variable if OFF if(!($p_f > 0)) { // This variable is set to zero for the first page $p_f = 0; } $p_fwd=$p_f+$p_limit; $p_back=$p_f-$p_limit; //////////// End of variables for advance paging /////////////// /////////////// Start the buttom links with Prev and next link with page numbers ///////////////// echo "<table align = 'center' width='80%'><tr><td align='left' width='20%'>"; if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back'><font face='Verdana' size='2'>PREV</font></a>"; } echo "</td><td align='left' width='10%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0 and ($back >=$p_f)) { print "<a href='$page_name?start=$back&p_f=$p_f'><font face='Verdana' size='2'>PREV</font></a>"; } echo "</td><td align='right' width='10%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this1 < $nume and $this1 <($p_f+$p_limit)) { print "<a href='$page_name?start=$next&p_f=$p_f'><font face='Verdana' size='2'>NEXT</font></a>";} echo "</td><td align='right' width='20%'>"; if($p_fwd < $nume){ print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'><font face='Verdana' size='2'>NEXT</font></a>"; } echo "</td></tr></table>"; ?>
×
×
  • 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.