Jump to content

applebiz89

Members
  • Posts

    34
  • Joined

  • Last visited

Contact Methods

  • Website URL
    http://ashbanks.co.uk

Profile Information

  • Gender
    Not Telling

applebiz89's Achievements

Member

Member (2/5)

0

Reputation

  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.
×
×
  • 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.