Jump to content

hoogie

Members
  • Posts

    54
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

hoogie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. It looks like the problem is that you have this line in your query: WHERE id = $id But the variable $id is not set anywhere in the update page. This means that your query is trying to update all rows that have an empty id field, and since you probably don't have any rows with an empty id field, it's not updating anything. You need to pass the id to the update form using a hidden field, or some other method.
  2. One last question. Is this considered 'good' code?: return another_function('argument 1') && $compare || another_function('argument 2'); It seems unnecessarily obfuscated to me, but maybe that's because I'm just learning about it now. If your employee wrote something like that, would you consider it good code because it's simple, or would you want something more readable?
  3. Ok, this makes sense. I checked, and that function is NOT returning a boolean value, so that must be the problem. Thanks for the explanation!
  4. While going through an instructional book, I ran across some code that I didn't immediately understand. I've stripped it down to the relevant bits: function example($object_a, $object_b) { $compare = $object_a->id == $object_b->id; return another_function('argument 1') && $compare || another_function('argument 2'); } My first confusion was this line: $compare = $object_a->id == $object_b->id; Does this set $compare to TRUE if the ids match and FALSE if they do not? And the second confusion: return another_function('argument 1') && $compare || another_function('argument 2'); What is returned if the ids match? What is returned if they are different? When I try testing this out on my machine, it returns both functions whether or not the ids match, but I know that's not what's supposed to happen. Can anyone break this down for me? Thanks.
  5. PHP has some chart libraries, but from what I've seen they aren't as pretty as what you posted. I'd take a look at jQuery plugins or the Google Chart API. Here's a few places to start: http://www.jscharts.com/home http://www.jqplot.com/ http://code.google.com/apis/chart/
  6. I've just been looking in the online PHP manual. But it's not clear why there are two different escape functions for mysql, or what they do differently.
  7. I apologize if this has been asked before. I'm trying to find out what exactly is the difference between mysql_real_escape_string() and mysqli_real_escape_string(), and haven't had much luck. So far I know that mysqli supports OOP, but mysql does not - are there other differences? Does mysqli escape % and _ characters (I don't think mysql does). I'm not working in an OOP environment, so does it matter which I use? Thanks.
  8. I might not be understanding your question, but here goes: If you want to filter by price range, your code is pretty close to working. On the page with the link, your link should look like this: <a href="www.domain.com.php?product=television&price=1-100">Price (1-100)</a> The code you posted should be changed to this: ini_set('display_errors', 1); error_reporting(-1); $query = "SELECT * FROM productfeed"; if(isset($_GET['description']) && !empty($_GET['description'] )) { $description = $_GET['description']; $query .= " WHERE description like '%$description%'"; } if(isset($_GET['price']) && !empty($_GET['price'])) { $price = explode('-', $_GET['price']); $lowPrice = (int)$price[0]; $highPrice = (int)$price[1]; $query .= " AND price BETWEEN $lowPrice AND $highPrice"; } $query .= " LIMIT 0, 10"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class='productdisplayshell'> <div class='productdisplayoutline'> <div class='productborder'><center> <a href='$link' target='_blank'><img src='$image' width=\"95%\" /></a> </center> </div></div> <div class='productdescriptionoutline'> <div class='productdescriptionbox'> <a href='$link' target='_blank' >$description</a> </div> <div class='productfulldescriptionbox'>$fulldescription</div> </div> <div class='productpriceoutline'> <div class='productpricebox'> <center>&#163; $price</center> </div> <div class='productbuybutton'> <center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center> </div> </div> </div>"; } if ($_GET['description'] == $description ) { echo 'Sorry, this product is not available. Please visit our <a href="http://www.ukhomefurniture.co.uk">Homepage</a>.'; } if( !$result = mysql_query($query) ) { echo "<br>Query string: $query<br>Produced error: " . mysql_error() . '<br>'; } ?> <?php function sanitizeString($string) { return mysql_real_escape_string($string); } $description = sanitizeString($_GET['description']); $query .= " WHERE description like '%$description%' LIMIT 0, 10"; ?>
  9. At first glance, your problem might be that "LIMIT 0, 10" needs to go at the end of the query. You're tacking on the price AND statement AFTER your LIMIT statement.
  10. It might be time to show some of your code so we can see what's going on.
  11. I think using a mysql database would generally be faster than reading and writing text files - especially if the site gets heavy usage, or if you are going to end up storing a lot of data (saved chats, etc). Another thing to think about is that only one process can write to a file at a time, so if you have 10 users who all do something at about the same time, the person who clicked last will have to wait until all the other users' code has been processed before his will be. My vote would be for mysql.
  12. No, unfortunately not. That would be in the PHP source code, which we can't see. You could always try contacting the owner of the site - if they're not too worried about competition maybe they'd be willing to tell you what they're using.
  13. You can certainly do it this way if you like. To me it would make more sense to use a "sort" variable to the URL instead of a "price" variable. That way you could use one variable for all your links: www.domain.com.php?product=television&sort=price www.domain.com.php?product=television&sort=title www.domain.com.php?product=television&sort=date etc. Just keep in mind that it's really easy for users to enter malicious code in your URL, so be sure to escape these variables before using them in your database.
  14. A lot of times these sorts of sites get their data from a database that is maintained by a third party. For instance, my friend has a website where you can book hotel rooms. It has deals on hotels all across the country. But he doesn't get information from every hotel site or anything like that, he just pays this other company to use a database that they have put together with the information from all of those hotels. When the hotels want to add or change a deal, they just contact that company, the company changes their database, and then every website that uses their database updates automatically. Anyone who is willing to pay can use this database for their site, which is why so many hotel deals sites have the same deals listed. I'm assuming that this site uses something similar.
  15. Just create a new .php file and put the connection information in there. For added security, you can save it outside your document root (more info on that here if you're interested: http://www.tuxradar.com/practicalphp/17/1/3). Then, when you need to run a query, just include that file before the query is run.
×
×
  • 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.