Jump to content

applebiz89

Members
  • Posts

    34
  • Joined

  • Last visited

Everything posted by applebiz89

  1. Depends how you want to enlarge the image - you won't be able to do it with just PHP. Look into using the Fancybox or Lightbox plugin - http://fancybox.net/ It's as simple as pointing to the larger image and putting a class on your image tag - the plugin will do the rest
  2. If your not sure of the output of the result for getOrdersWithInformation() - wrap a conditional statement around your foreach, checking that the result of getOrdersWithInformation() is an array, so the foreach loop isn't instantiated and causing any errors if the result is false...
  3. Just wanted some general advice/guidance, I know there are plenty of articles and tutorials online about unit testing, but I just wanted to get a first hand perspective off of some of you guys... What are some real world examples of actual PHP Unit Testing? Also any unit testing frameworks you can recommend? Apologies if this has been covered before.
  4. probably an error on line 6 or could even be 9
  5. on the page you want to display the news, i assume you will have a listing. say the url to link to the news page is news.php?id=1 <- the primary key of the news article. then on that page you will use a query like: select * from news where pkID = $_GET['id'] thats what they mean by using the get.
  6. im sorry, I don't understand your example. Could you explain more please
  7. I am trying to write a shopping cart script, that once they have confirmed their order it will insert into the database their order information. Basically as a product can have a number of different quanitities that they wish to purchase, I want to create an associative array that has a product, linked to the quantity. I want to do this so that the order information stays in one row in the database, so in the 'product' row, it has values like (cow -> 2) cow being the product and 2 being the quantity. Here is the code I am developing, and I have commented in the array which I am trying to create just the show my idea of thinking. any help, will be greatly appreciated! function updateCart($product_id,$id){ if($_SESSION['cart']) { foreach($_SESSION['cart'] as $product_id => $quantity) { $total = 0; $sql = sprintf("SELECT title, price, shipping FROM product WHERE pkID = %d;",$product_id); $result = query($sql); if(numRows($result) > 0 ){ $row = getResult($result); $price = $row['price']; $shipping = $row['ship']; $line_cost = ($price + $shipping) * $quantity; $total = $total + $line_cost; $product[] = $row['title'] -> $quantity; //unsure of how to code $sql2 = "INSERT INTO cart (userID, products, total, date) VALUES ('$id', '$product', '$total' '$date')"; $query = query($sql2); } } }else{ $alert = 'No items in shopping cart.'; } return $total; }
  8. I have this function, but it doesnt work. Basically the list outputs a list of news features, and puts a line under neath each article to seperate them. However once the last article has been reached, I don't want the break to be shown. this is my code, any help would be appreciated as i am really struggling on this. Just need to determine the last item in the array, and stop the <hr split> from being output. function newsFeature(){ $event = "SELECT imgname, title, content, pkID from news ORDER BY date, time DESC LIMIT 5"; $event_page = query($event); $count = numRows($event_page); while ($row = mysql_fetch_assoc($event_page)) { $rowcount = $count; $para = substr($row['content'] , 0,100); $result .= '<article>'; $result .= '<a href="news-article.php?pkID=' . $row['pkID'] . '"><img src="uploads/thumbs/' . $row['imgname'] . '" alt="" width=116 height=83/ ></a>'; $result .= '<h2><a href="news-article.php?pkID=' . $row['pkID'] . '">' . $row['title'] . '</a></h2>'; $result .= '<p>' . $para . '...</p>'; $result .= '<p><a class="read-more" href="news-article.php?pkID=' . $row['pkID'] . '">Read more<span></span></a></p>'; $result .= '</article>'; if($row != end($row[])){ $result .= '<hr class="split">'; } } return $result; }
  9. I want to make the form so only people with a specific email address can sign up to the site. So for example their ending email address was.... @something.apple.biz.com .. but to be accepted into the site, the email HAS to end with apple.biz.com. How could you validate it so it matches something specific like this. Here is my code at the moment which just checks that their is at least one . after the @ for it to be an acceptable email. If anyone could say what else to add to do this would be great if($email != '' && $register){ $emailcheck = explode("@", $email); $sql = "SELECT email FROM member WHERE email='$email'"; $query = mysql_query($sql); $emails = mysql_num_rows($query); if($emails != 0 ){ $alert .= '<p class="alert" style="clear:both;">That email address has already been registered</p>'; $register = false; }elseif(count($emailcheck) != 2){ $alert .= '<p class="alert" style="clear:both;">Please enter a valid email address</p>'; $register = false; }elseif(count($emailcheck) == 2){ $emailchecktwo = explode(".", $emailcheck[1]); if(count($emailchecktwo) < 2){ $alert .= '<p class="alert" style="clear:both;">Please enter a valid email address</p>'; $register = false; } } }
  10. it does as im running it locally it must be the code, everything look fine in the code then? I think its because im trying to use to move files
  11. I have a form that lets a user upload an image, aswell as another file. I want the image to go into the images directory, and the pdf file to go into the PDF directory once uploaded. The names of the files will then be uploaded to the database. At the moment I can get the image to upload to the database and directory, but the PDF is only uploading the name to the database, it is not going into the PDF directory aswell. I'm not sure if there is a way you can do this, I am trying to use "move_uploaded_file()" to physically move the files but not sure if you can use it twice. here is my code, if you can point anything out or where im going wrong that would be great. <?php include "include/conn.php"; include "include/session.php"; ?> <?php // Check to see if the type of file uploaded is a valid image type function is_valid_type($file) { $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif"); if (in_array($file['type'], $valid_types)) return 1; return 0; } function showContents($array) { echo "<pre>"; print_r($array); echo "</pre>"; } //Target path for image $TARGET_PATH = dirname(__FILE__) . "/images/"; //Target path for PDF files $PDF_TARGET_PATH = dirname(_FILE_) . "/PDF/"; // Get POST variables $image = $_FILES['image']; $pdf = $_FILES['pdf']; $date= date("Y-m-d "); $time = date("H:i:s"); $title = $_POST['title']; $title_escape = mysql_escape_string($title); $title_slashes = stripslashes($title_escape); $content = $_POST['content']; $image['name'] = mysql_real_escape_string($image['name']); $pdf['name'] = mysql_real_escape_string($pdf['name']); //image path $TARGET_PATH .= $image['name']; //PDF path $PDF_TARGET_PATH .= $pdf['file_name']; // Make sure all the fields from the form have inputs if ($image['name'] == "" ) { $_SESSION['error'] = "All fields are required"; header("Location: add_media.php"); exit; } // Verify file is an image if (!is_valid_type($image)) { $_SESSION['error'] = "You must upload a jpeg, gif, or bmp"; header("Location: add_media.php"); exit; } // move file into the directory and the path name into the database / along with the rest of the form fields if (move_uploaded_file($image['tmp_name'], $TARGET_PATH)) { if(move_uploaded_file($pdf['tmp_name'], $PDF_TARGET_PATH)) { $sql = "INSERT INTO media_table(title, text, time, date, image, PDF) VALUES ('" . $title_slashes . "','" . $content . "', '" . $time . "', '" . $date . "', '" . $image['name'] . "', '" . $pdf['name'] . "')"; $result = mysql_query($sql) or die (mysql_error()); header("Location: add_media.php"); exit; } else { print "did not upload"; } } else { $_SESSION['error'] = "Could not upload file. Check read/write persmissions on the directory"; exit; } ?>
  12. I wish to allow users to comment on an article on my site. However I wish to make it so that: A user writes a comments and then submits it, the comment then goes to an email OR a page where an admin can read through them, and tick and confirm whether they are 'suitable' to be posted. Once a comment is confirmed then to show it on the page. If I went for the approach of putting it on a page where all comments are, would it be a good idea to put a radio button next to each comment to say 'confirm' or 'reject' and this go straight to the database...also maybe an email when a new comment is posted so that the admin can then go and check new comments.... any ideas or help would be grateful, just trying to get my head round it. cheers
  13. cheers mate, nice one. How can I ensure the image column always has 'default.jpg' in it, im using phpMyAdmin. also would having that automatically ensure that the article can be uploaded as a picture will always exist or should i add an if statement to the script?
  14. hi there, Im running into a dead brainer here. I want to allow users to upload an article, and in this article have text and an image. So the article will have a title, image and content. Hard to describe, but my problem is this: Uploading these from a form, so that in the database they appear in just one row together, so the image and text is linked to the title of the article. How could I go about doing this, as the ID's of the articles will automatically be generated, im not sure how i could code is so that all of these are specific to their id's. I have this image upload script already from another use site i have developed and have start to re work it, but wondering how i could adapt this with a form with more than just the image upload in it. Sorry if sounds bit complicated, hard to word what im thinking thanks in advance <?phprequire("include/conn.php");include "include/session.php";// Check to see if the type of file uploaded is a valid image typefunction is_valid_type($file){ $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif"); if (in_array($file['type'], $valid_types)) return 1; return 0;}function showContents($array){ echo "<pre>"; print_r($array); echo "</pre>";}$TARGET_PATH = "images/";// Get POSTed variables$image = $_FILES['image'];$image['name'] = mysql_real_escape_string($image['name']);$TARGET_PATH .= $image['name'];// Make sure all the fields from the form have inputsif ($image['name'] == "" ){ $_SESSION['error'] = "All fields are required"; header("Location: addvox.php"); exit;}// Verify file is an imageif (!is_valid_type($image)){ $_SESSION['error'] = "You must upload a jpeg, gif, or bmp"; header("Location: addvox.php"); exit;}// move file into the directory and the path name into the databaseif (move_uploaded_file($image['tmp_name'], $TARGET_PATH)){ $sql = "UPDATE vox SET image = '" . $image['name'] . //where id = 'VOX_ID'; $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error()); header("Location: user-page.php"); exit;}else{ $_SESSION['error'] = "Could not upload file. Check read/write persmissions on the directory"; exit;}?>
  15. I'm not sure how to word it better. I want all of them. So the form has four fields; the ones i mentioned. I want it so...the user can search for a member with age=z name=y and instrument = q, however if they just want to search for an age on its own they can. If I use as you said an AND, it means that all search fields have to be satisfied otherwise it returns no results. If I use OR results for any of them fields will come back...so if I searched age-18 and instrument-guitar. Using OR would return everyone with the age 18 aswell as anyone who plays guitar not strictly someone who is 18 and who plays guitar. I know the solution for this would be AND as you said, but once you add more search fields in it becomes harder as all of these have to be filled in. I want it so that they can pick and choose what they search..in the one form. Just like most searches work on other sites.
  16. I have a search form on my site where a user can search for other members. I have a criteria of: age, name, instrument, purpose I want the search so that if a user selects for example; age - 18 and instrument - guitar. It comes up with the results of everyone with this. The same goes for having a search for all of the criteria as well as say only by the members name. However if I use a select statement where I use AND, so 'SELECT * FROM profiles WHERE age = $age AND name=$name AND instrument = $instrument"; It will only come up with a result if ALL the search fields are input. With OR it will always come up with a result, but I want this search to be specific and allow the user to either just search one field, or all of them and come up with a result that meets this criteria. So what I'm saying is, is there anyway to integrate AND and OR together so I can meet this all in one search form.. Thanks applebiz
  17. ive got it working! thanks guys, i was just getting confused a bit there, my mistake cheers!
  18. yeah thats right, but Im confused as to how to make the <href ...> link, link to the usernames that are found to in the search. So, say I was to search for 'David' and each person to have the name david came out with the list applebiz gary123 jimmy123 so all these usernames are members called david. I want to link to page-view.php automatically by their username to display all their information without physically writing 'page-view.php?username=applebiz' because I don't know their username yet as it is in the search
  19. yes, it works when i for instance use 'profile-view.php?username=gary' . So i know it works, but how can i parse the usernames that come up in the search so it uses that usernames information
  20. <?php $username=$_GET['username']; $result=mysql_query("SELECT * FROM musicians WHERE username='$username'"); while($row = mysql_fetch_array($result)) { echo $row['username'] ; echo $row['firstname'] "; echo $row['lastname']; echo $row['email'] "; echo $row['age'] ; echo $row['instrument']; echo $row['location'] "; echo$row['postcode'] ; echo $row['genre']; } ?> This code does output what I want it to do when I call it by a specific username. But as i said i want it to work so that the username that appears in the search then links so their information is displayed by their username passed over. Thanks
  21. Ive put the spaces together and it opens the page but the select statements in the profile-view.php arnt picking up the $username variable. Anything else anyone can suggest?
  22. HI guys, if anyone could point us in the right direction of how to do this, or provide some test code for a similar problem would be great! Basically, I have user profiles on my site, and I have a search by for example firstnames will list all usernames with the first name 'bob'. With this list I want to turn the output of each name to a link to their profile. the profile page is profile-view.php and I am using the statement "select username from members where firstname = $input"; and $num_results = mysql_num_rows($result); $username = $row['username']; for ($i=0; $i <$num_results; $i++) { $num_found = $i ; $row = mysql_fetch_assoc($result); echo "<a href='profile-view.php?username = $username'>{$row['username']}</a><br/>"; } I know the <a href> wont work, but is there anyway of being able to do this, all usernames are unique across the site too thats why I thought the link it by this. Thanks in advance
  23. This is taken direct from phpMyadmin so sorry for format. but should get the Jist firstname varchar(25) latin1_general_ci Yes NULL lastname varchar(25) latin1_general_ci Yes NULL DOB date Yes NULL username varchar(50) latin1_general_ci No None password char(32) latin1_general_ci No None instrument varchar(25) latin1_general_ci Yes NULL location varchar(25) latin1_general_ci Yes NULL postcode varchar( latin1_general_ci No None genre varchar(25) latin1_general_ci Yes NULL aboutsection text latin1_general_ci Yes NULL picture blob BINARY Yes NULL Field Type Collation Attributes Null Default Extra Action id varchar(50) latin1_general_ci No username varchar(10 )latin1_general_ci No ip varchar(20) latin1_general_ci No tm datetime No 0000-00-00 00:00:00 status char(3) latin1_general_ci No ON Anyways I realised how to do this by using this statement: SELECT * FROM musicians WHERE username='$_SESSION[username]'; and then putting this into an array and echoing each attribute... but one question. is there anyway of putting this into a nice 'profile' sort of format. So can I just use the 'echo "<td>" . $row['username'] . "</td>";' code in perhaps a table structure..
  24. hey, I have two tables in my mySQL database: login and musicians(which is basically members of the site) the sign up information goes to the musicians table and, when a member logs into the site their session goes into the login table with their sessionID,username,ip and time they logged in. My problem is that once they have logged in, they get directed to their 'profile' page so they can view the information they inserted into the sign up form. How can I collect the information that is this users; so it queries the database by the username that is in the sessionID and gathers the information held in the musicians table, if that makes sense... if there is any other way you can suggest or help that would be great. Just trying to get my head round it. Thanks
  25. Hi there, not sure if this is the right section or not. However, I am creating a social networking type site, although once the user has created their profile, I want to have a flash player to allow them to upload and play their songs for others to listen to, much like myspace. so my question is, is there any flash players available to do this to an outside website other than mine, or one that allows the upload to go to the database of my website. Also if there isnt one, and I create it myself, how could I link the individual songs that are uploaded to my database to the flash player... sorry for the complicated question, just trying to say what Im thinking here. So in short Im basically asking how would it work to embed a flash player onto a social networking site, so that the user can upload songs to the database, but only his songs hes uploaded go to the flash player thanks in advance
×
×
  • 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.