Jump to content

Andy17

Members
  • Posts

    249
  • Joined

  • Last visited

    Never

Everything posted by Andy17

  1. Hey guys, Firstly, this is not solely about PHP, but rather a mixture of jQuery, JSON, PHP and MySQL, but I hope it's OK to post it here. I am sending data to a PHP script via the jQuery ajax function. The data is encoded in JSON and then decoded in the PHP script. This all works great. However, I noticed that one of my queries does not work with certain characters in the data (more specifically the Danish characters æ, ø and å). The query works with other data except those. The query also works if I hard code the data into the PHP script, even if it contains any of the three mentioned characters. This leads me to believe that the problem is somehow connected to character sets when sending data from one page to my PHP script with jQuery. The page from which the data is sent to the PHP script has a charset of iso-8859-1 and the columns utf8_danish_ci. I can indeed see that those are not the same, but I have tried to use the PHP uft8_encode() function in my PHP script, but without luck. I have not posted any code because I don't really find this relevant in relation to my problem. Can anyone think of a way to solve this without changing charset on the page from which the data is sent from (to the PHP script)? Thanks in advance, Andy
  2. I'm not 100% sure I understand what you want. But, if you have a product which has a single manufacturer associated with the product, you can simply have a foreign key in your product table that references a column in a manufacturer table. So, a query could look like this: SELECT * FROM Manufacturer WHERE ManufacturerId = (SELECT ManufacturerId FROM Product WHERE someUniqueColumn = 'someUniqueValue') That would give you the manufacturer details for a given product. As I was reading your post again, it seems like I misunderstood what you wrote, but I hope the above is of any help anyways - otherwise I will have to try again.
  3. I already said to notice the orange border in that screenshot. It finds the correct values, but for some reason, I only have access to the Name column. When I try to echo out the other columns in PHP, nothing is displayed.
  4. You're welcome - glad I could help.
  5. I didn't read what you are doing too much, but I hope the below will be useful anyways (the principle). You could put a column in your current table (I will assume that it is named "Booking") named something like "pageId" and then make a new table named "Page" with the following columns: pageId, pageName. You should of course add more if you find some useful - a description for instance. Then add a foreign key from Booking.pageId to Page.pageId. So, each row in your "Booking" table has a reference to a Page row. This means that you can have different pages for different bookings. So, you should be able to do something like this: $query = "SELECT b.field1, b.field2, b.field3, b.pageName FROM Booking b, Page p WHERE b.someUniqueField = 'someValue' AND p.pageId = b.pageId"; // Some code omitted while($rows = mysql_fetch_assoc($result)) { echo '-Title: <a href="' . $rows['pageName'] . '.php" alt="' . $rows['title'] . '">' . $rows['title'] . '</a><br/>-Author: ' . $rows['author'] . '<br />'; } Excuse me if I made some simple syntax mistake above. But, now you should be able to associate a given booking row with a page and link to that page. Good luck!
  6. Just a security note; as users can easily modify the id value and therefore do SQL injection, I strongly suggest doing like below: $id = mysql_real_escape_string($_GET['id']); $sql = "select * from book where title_id = " . $id; You probably already know this, but just making sure he does not make this mistake.
  7. (Just so you don't have to scroll) Let's say that I have the following ContentTypes with some descriptions: News Videos Pictures For each of those ContentTypes, I have associated ContentCategories (which is done in the many-to-many relation named TypeCategory). So, the ContentType "News" could have the following categories: Sports Crime Celebrities Gaming ... and the "pictures" ContentType could have different categories associated with it. So on a page I want to display the categories a given ContentType has associated with it. If this ContentType was "News", I would want the query to return the rows in ContentCategory that are associated with it. In this example, I would want it to return the categories given above (sports, crime, celebrities, gaming - and their Description and CategoryNum). My query finds the correct categories associated with the ContentType I provide, but it only returns the category's Name and not Description and CategoryNum, which I also need (notice the orange border around the Name column in the phpMyAdmin screenshot in the first post). I hope that helps.
  8. Hey guys, I am building a new website and have a query that I want to return multiple columns, but it only returns one. Before I start explaining too much, here is the relevant part of my database diagram: What I want to do is to select the Name, Description and CategoryNum from the ContentCategory table that corresponds to a given ContentType row. For example, let's say that I have a ContentType row with the name "News". I would then want to find the categories associated with that type in the ContentCategory table. So, there are a number of categories associated with different types of content. Here is my query: SELECT cc.Name, cc.Description, cc.CategoryNum FROM ContentCategory cc INNER JOIN TypeCategory ON cc.CategoryId = TypeCategory.CategoryId INNER JOIN ContentType ON ContentType.ContentTypeId = TypeCategory.ContentTypeId WHERE ContentType.ContentTypeId = 'News' The Name column in ContentType is unique. I have some test data in my tables. I get the correct row, but it only selects the Name column from ContentCategory as shown below. I am pretty new to inner joins and using many-to-many relations, so I would really appreciate if anyone can tell what I am doing wrong. If it helps anyone, here is my table structure: CREATE TABLE ContentType ( ContentTypeId int NOT NULL auto_increment, Name VARCHAR(20) NOT NULL, Description VARCHAR(150) NOT NULL, PRIMARY KEY (ContentTypeId), UNIQUE (Name) ) CREATE TABLE TypeCategory ( ContentTypeId int NOT NULL, CategoryId int NOT NULL, PRIMARY KEY (ContentTypeId, CategoryId), FOREIGN KEY (ContentTypeId) REFERENCES ContentType(ContentTypeId), FOREIGN KEY (CategoryId) REFERENCES ContentCategory(CategoryId) ) CREATE TABLE ContentCategory ( CategoryId int NOT NULL auto_increment, Name VARCHAR(50) NOT NULL, Description VARCHAR(500) NOT NULL, CategoryNum int NOT NULL, PRIMARY KEY (CategoryId), UNIQUE (Name, CategoryNum) ) Thanks a lot in advance! Andy
  9. This should work (with MySQL or PostgreSQL): SELECT * FROM YourTable ORDER BY TableId ASC LIMIT 1 OFFSET 20 Replace the 20 with 11 for getting the 12th row.
  10. Yeah, I was thinking that it had something to do with that function. I don't know why I didn't look it up. Guess I was too frustrated. Anyways, after reading what you wrote, I made it work by using the file_get_contents function instead. Thank you very much for your help.
  11. Wow, I didn't even think of that. Thanks for pointing that out. Smooth, that seems to work. Thanks a lot.
  12. I hope that subject made sense! I have a page where I want to generate page-specific keywords automatically. Actually I have some general keywords stored in a text file and then I add the page-specific ones after those. The problem is, however, solely caused by the keywords I pull from my text file. A "1" is added to my list of keywords. Consider a news page like so: news.php // ... <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="<?php require('php/generateKeywordList.php'); ?>" /> </head> // ... And then generateKeywordList.php // I have omitted the part with the page-specific keywords, because it is not what causes the problem (commented it all out) set_include_path('/mypath/'); $str = require_once('includes/websiteKeywords.txt'); echo $str; // For some reason, the number 1 is added at the end of this string websiteKeywords.txt (it doesn't matter what I put in there) these, are, my, keywords, for, my, website In my meta tag, the above would be displayed as: these, are, my, keywords, for, my, website1 I then tried to make a simple php page like this $keywords = require('includes/websiteKeywords.txt'); echo $keywords; ... and it worked. At the moment I have absolutely no idea where the number 1 comes from. So, basically if I include the keywords directly from the text file into my meta tag, it displays fine. If I make a simple php page where I echo out the keywords from the text file, it displays fine. But if I include my php script, which echos the keywords, into my meta tag, the number 1 is added at the end of the string. Am I completely missing something here or is this extremely strange? Thanks for any help!
  13. Hey I'm pretty new to regular expression, so I might have made a silly mistake. I want to check if there are any symbols/special characters (not letters or numbers) in a string. I have the code below. function validateKeywords($kw) { if (preg_match("/[^A-Za-z0-9]/", $kw)) { echo 'validation of keywords failed<br />'; return false; // String contains symbols (not letters or numbers) - incorrect format! } else { echo 'validation of keywords succeeded<br />'; return true; // Correct format } } // Testing validateKeywords('some random string I wrote for testing purposes'); // should succeed validateKeywords('some random 10 string I wrote for testing purposes 2010'); // should succeed validateKeywords('some random, string, I wrote for 19 testing purposes'); // should fail validateKeywords('some, random, string I wrote, for testing purposes'); // should fail The problem is that all 4 calls return false and print that the validation failed. So, where did I mess up? Thanks!
  14. Andy17

    XSD and DTD

    Hey guys, So I have started to learn a bit of XML and saw w3schools having tutorials for both XSD (XML Schemas) and DTD (Document Type Definition) for describing the structure of an XML document. Before I begin learning both of these, I would like to know if it is necessary to know both of these markups, or if one of them is used more than the other. So, should I spend time on learning both of them or just one (if so, which one is most used?). Thanks! Edit: Sorry, this just might have been posted in the wrong forum. There are really some categories missing on this forum.
  15. Hello, I have a few domains with no content on them except Google Domain Ads and I have not linked to them from any other websites. I keep the domains for future use in like 1-2 years for a business. I was wondering if it would be a good idea - SEO wise - to link to them from forums for example, even if they have no content. I realize that it would affect what people think of my site, but I am strictly thinking about the SEO part. My own guess is that it doesn't really matter since it has no content, but I could be wrong. Perhaps it's good to start building up a "network" of linking sites as early as possible. Or maybe I could be "punished" by search engines for having an empty site? I don't know - do you? Thanks in advance! Andy
  16. I was having a few problems with it, but it seems as if I resolved it. Thanks a lot for the link - that's pretty cool!
  17. Hello, I have a small and annoying problem. Imagine that I have a main folder on my FTP server which has index.php and I then have a php folder for all of my small scripts and an includes folder for misc files. So, for instance http://www.somedomain.com/index.php http://www.somedomain.com/php/somescript.php http://www.somedomain.com/includes/somefile.html Inside somescript.php, I need to use one of the files from the includes folder, like this for example: require('../includes/somefile.html'); This is all fine, but the problem is when I include the PHP file on my index.php page. Then I am telling PHP to go one step back to find the includes folder, but the problem is that it only needs to go one step back if it PHP script is not included on some page outside of the php folder. If I run php/somescript.php, there is no problem, but if I include php/somescript.php on my index.php, then there is trouble! I hope you guys understand what I mean. Thanks in advance! PS - I would appreciate if the solution is not about moving php/somescript.php or using full URLs in my includes.
  18. Yes, I realized that is what was causing the problem. Actually I was looking for a way to include exceptions with htmlentities() because I have always been told that's the best one to use. Thanks, your code was good inspiration for me, but I decided to not use htmlspecialchars when inserting data. I am inserting my data 100% clean and original, except when I use mysql_real_escape_string. Then I take all of the needed security precautions (I hope) before displaying the data. It won't harm my database anyways. I did like this: function stripdata($data) { return trim(htmlentities(stripslashes($data), ENT_QUOTES)); } function showStyling($data) { $data = str_replace('[b]', '<b>', $data); $data = str_replace('[/b]', '</b>', $data); $data = str_replace('[u]', '<u>', $data); $data = str_replace('[/u]', '</u>', $data); $data = str_replace('[i]', '<i>', $data); $data = str_replace('[/i]', '</i>', $data); return $data; } echo nl2br(showStyling(stripdata($row['text']))); Thanks a lot for your post - it was a great help!
  19. Hey guys, OK, so actually I have two questions that are kind of related. The first one is how I can allow users to use <i>, <b>, <strong> tags when submitting information in a form. I would like to allow certain tags so they can emphasize things in their text, but I still want to strip the rest for security reasons. I tried using strip_tags() with some exceptions as a second parameter, but as far as I understand, that just allows them to be displayed as text, not for the browser to make text bold for instance. Below is what I have now. function stripdata($data) { return trim(htmlentities(stripslashes($data), ENT_QUOTES)); } echo stripdata($someDataFromMySQL); I also want to ask if the solution above is 100% safe so that users can not submit malicious code that can execute when users' visit a page of mine that displays that code. Thank you in advance.
  20. OK, I'm a bit of a newbie at PHP and I didn't read everything you wrote too well, but perhaps you can do something like this. for ($i = 0; $i < count($yourArray); $i++) { $yourArray[$i] = null; } That's a suggestion to solve a part of your problem. Hope it helps one way or another - otherwise you will have to wait a little longer for one of those geniuses to come around.
  21. $row2 = mysql_query("SELECT * FROM ax_music ORDER BY 'sort' ASC"); Aren't you missing a WHERE clause? Also, you should really use mysql_real_escape_string() when you grab a value for a query from the URL ($pageNum).
  22. Ah yeah, that's right. I remembered that it was something strange. Thanks.
×
×
  • 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.