-
Posts
279 -
Joined
-
Last visited
Everything posted by Fluoresce
-
Will I See the MySQL Error or the PHP Error?
Fluoresce replied to Fluoresce's topic in PHP Coding Help
Thanks for the help! I use die() at the end of every mysql_connect() and mysql_query(), thus: $con = mysql_connect("localhost", "", "") or die(mysql_error()); $result = mysql_query($sql, $con) or die(mysql_error()); Are you saying that, once I get the code working, I should remove die()? Is there no chance that mysql_connect() or mysql_query() will fail in the future? I understand that I should remove it if I already have something more user-friendly dealing with the error, but what if I don't have such a thing in place? -
if(mysql_num_rows($results)) { $sql = "UPDATE `table` SET `column` = '123' WHERE `id` = 1 LIMIT 1"; $update = mysql_query($sql, $conn) or die(mysql_error()); if($update) { echo "<p>The table has been updated successfully.</p>"; } else { echo "<p>Sorry, an error occurred. Please try again.</p>"; } } I wrote the bit of code above. It works, but there's something about it that I don't understand. If the update were to encounter an error, will I see the MySQL error message or the else statement error message? How would you have written this code? How could I have deliberately caused an error to see what happens? I appreciate the help that I get on this site very much. Learning loads!
-
Thanks! Never heard of XSS injections. I already had mysql_real_escape_string() in place. I don't like CAPTCHA. I used the following code instead. How secure will it make my form? Anyone know? This is on submit.php: <input type="hidden" name="loadtime" value="<?php echo time(); ?>"> And this is on the page that processes submit.php: $loadtime = $_POST["loadtime"]; $totaltime = time() - $loadtime; if($totaltime < 7) { echo("Please fill in the form before submitting!"); die(); } Basically, if the form is submitted before 7 seconds, a message is presented and the script is ended. Since bots submit forms quickly, this should be quite effective at stopping spam submissions, right?
-
I have a form on my site that allows people to submit information to my database. At the moment, the form has no protection. What risks am I facing? Is it just spam bots, or are there other risks? What's the best way of dealing with the different risks? Do CAPTCHAs actually work, or are there better alternatives? How do you protect and maintain your database?
-
How Can I Display Categories and Articles in Alphabetical Order?
Fluoresce replied to Fluoresce's topic in PHP Coding Help
Thank you guys very much! I appreciate your assistance. I learn loads in this forum! And a big thank you to you, Psycho, for the code.- 4 replies
-
- alphabetical order
- mysql select
-
(and 1 more)
Tagged with:
-
Can you figure this out? I've got two tables, `articles` and `categories`. Each article has been assigned to a category. I want to present all of the articles on a single page, one list per category, thus: Category Article 1 Article 2 Article 3 Article 4 Category Article 1 Article 2 Article 3 Category Article 1 Article 2 Article 3 Article 4 I want the categories to be in alphabetical order and the articles to be in alphabetical order. So far, I have only managed to get the categories in alphabetical order. How can I also get the articles in alphabetical order? As always, any help will be much appreciated. Here's my code: $sql = "SELECT title, url, cat FROM `articles` LEFT JOIN `categories` ON articles.catid = categories.catid ORDER BY cat ASC"; $results = mysql_query($sql, $conn) or die(mysql_error()); if(mysql_num_rows($results)) { $last_cat = ''; while($row = mysql_fetch_assoc($results)) { if($row['cat'] != $last_cat) { if($last_cat) { echo "</ol>"; } $last_cat = $row['cat']; echo "<h3>$last_cat</h3>"; echo "<ol>"; echo "<li><a href=\"{$row['url']}\">{$row['title']}</a></li>"; } else { echo "<li><a href=\"{$row['url']}\">{$row['title']}</a></li>"; } } echo "</ol>"; } else { echo "<p>No articles found.</p>"; }
- 4 replies
-
- alphabetical order
- mysql select
-
(and 1 more)
Tagged with:
-
Thanks, guys, but using a dark background colour makes no difference. The problem that I am trying to fix is that, every time I click from one page to another using IE 10, I can see the dark background image of the body tag reload very quickly, before the light foreground colours kick in. If I add a dark background colour to the body tag, I will still see a dark background appear very quickly before the foreground colours kick in. What's confusing me is that you guys aren't seeing the same problem. When you check my site, are you using IE 10 with the default settings?
- 6 replies
-
- internet explorer
- background image
-
(and 2 more)
Tagged with:
-
Thanks for the reply. My IE 10 cache settings are at default: "Check for newer versions of stored pages" is set to "Automatic". "Allow website caches and databases" is checked. What are your settings? When you click from page to page, doesn't the dark body background image have to reload every time? The only way around this problem that I can think of is having a light background image, which I don't want. Any ideas on how this can be fixed? Thanks, but setting the page's background to a dark color doesn't help. And thanks for Fiddler2, too. It looks like a cool bit of software.
- 6 replies
-
- internet explorer
- background image
-
(and 2 more)
Tagged with:
-
This problem is driving me crazy! I have been browsing my site using IE 10, just to see how it looks. Every time I click from one page to another, the body background image appears and disappears very quickly, as if it has to re-download for every page. Browsing the Web, I discovered that this is a common problem. Apparently, IE doesn't cache background images properly or something. I found a variety of "fixes". I tried them all and none of them have worked, including these three: <img src="images/dark-texture.jpg" style="display:none" /> <META http-equiv="Page-Enter" content="blendTrans(Duration=0.1)"> <META http-equiv="Page-Exit" content="blendTrans(Duration=0.1)"> <!--[if IE]> <meta http-equiv="Page-Enter" content="blendTrans(duration=0)" /> <meta http-equiv="Page-Exit" content="blendTrans(duration=0)" /> <![endif]--> Do you guys know how to fix this problem? My body CSS styling looks like this: body { font-family: Verdana, Helvetica, FreeSans, Sans-serif; font-size: 100%; padding: 0; margin: 0; background-image: url(images/dark-texture.jpg); } My website is Self Help Videos.
- 6 replies
-
- internet explorer
- background image
-
(and 2 more)
Tagged with:
-
How do I identify if a number starts with a zero?
Fluoresce replied to Fluoresce's topic in PHP Coding Help
Thank you for clearing that up! -
How do I identify if a number starts with a zero?
Fluoresce replied to Fluoresce's topic in PHP Coding Help
Thanks! Works well. By the way, I just like to be very thorough when it comes to SEO and avoiding duplicate content. I like to block every possible gap. The same content can't appear on more than one page. The way things were, Page 1's contents would appear on pages 01, 001, 0001, 00001, etc. These pages have to give 404 errors for me to relax. Quick newbie question. What's the difference between these? $page[0] == "0" $page[0] == 0 They both seem to work fine. -
I have pagination on my website. The URL looks like this: www.example.com/articles/1 The "1" is the page number. At the moment, I have about 15 pages. If someone manually changes the page number to, say, 16, my PHP script throws a 404 "page not found" error, which is what I want: if($pageNumber > $totalPages) { header("HTTP/1.1 404 Not Found"); include('404.php'); die(); } I also want a 404 if someone manually changes the page number to zero. This is quite easy to do: if(($pageNumber > $totalPages) || ($page == 0)) { header("HTTP/1.1 404 Not Found"); include('404.php'); die(); } All is well so far. The problem is that, today, I noticed that if someone changes the page number to 01, they will see Page 1; if they change it to 02, they will see Page 2; and so on. My question therefore is this: How do I throw a 404 if $pageNumber is a 2-or-more-digit number that starts with a zero?
-
You were right, mate. I thank you for your help! Everything's fixed now. I had to go through every page and change the URLs.
-
Instead of going through my entire website and changing every path to absolute, isn't there an edit I can make to my .htaccess file? I thank you for your attention.
-
I'm confused! Please let me explain my problem in more detail. All of the links on my website are relative, like this: <a href="contact-us.php">Contact Us</a> All of the CSS paths on my website are relative, too, like this: <link rel="stylesheet" type="text/css" href="style.css" /> I have links to videos on my website. They look like this: <a href="watch-video.php?id=12">How to Lose Weight</a> I want this link to look like this: <a href="/12/how-to-lose-weight/"></a> I have created a .htaccess file. It contains just these 2 lines: RewriteEngine on RewriteRule ^([0-9]+)/[A-Za-z0-9-]+/?$ watch-video.php?id=$1 [NC,L] The rewrite is working. The page watch-video.php is loading with the right video, but the page has no styling. And when I hover over the URLs on watch-video.php, they all include /12/how-to-lose-weight/, like this: <a href="www.mysite.com/12/how-to-lose-weight/contact-us.php">Contact Us</a> Are you saying that my .htaccess file is fine and that this is all normal after a rewrite? Do I just have to change all paths to be absolute? For example, do I have to do my video links like this: <a href="http://www.mysite.com/12/how-to-lose-weight/">How to Lose Weight</a>
-
Thanks but didn't work. Anyone else?
-
All of the links on my website now begin like this: www.example.com/12/how-to-lose-weight-fast/ So, for example, the URL for my contact page looks like this: www.example.com/12/how-to-lose-weight-fast/contact-us.php What is going on! How do I stop the rule from applying to every single URL on my website? Surely, it should only apply to URLs that begin with an ID number, right? Any help will be much appreciated.
-
I have to admit that I don't fully understand the flags that I have used. "NC" means case-insensitive, which means that is doesn't matter if someone uses the following URL, right? www.example.com/12/How-To-Lose-Weight-Fast/ They will still be served www.example.com/12/how-to-lose-weight-fast/. Is that correct? But what exactly does "L" mean? I know it indicates that "the current rule should be applied immediately without considering further rules." My question is, what current rule?
-
I'm new to mod_rewrite. I'm trying to rewrite my URLs, but it's not working. I have changed the URLs on my website to look like this: <a href="/id_number/hyphenated_article_title/">Anchor_text</a> E.g., <a href="/12/how-to-lose-weight-fast/">How to Lose Weight Fast</a> My .htaccess file looks like this: RewriteEngine on RewriteRule ^/([0-9]+)/[A-Za-z0-9-]+/?$ article.php?id=$1 [NC,L] The rewrite is working, but article.php is loading slowly and without CSS styling. Anyone know why?
-
How do You Echo a Different List Every Day, Automatically?
Fluoresce replied to Fluoresce's topic in PHP Coding Help
Thanks, PaulRyan! The code worked well. Learnt loads from it, too. -
How do You Echo a Different List Every Day, Automatically?
Fluoresce replied to Fluoresce's topic in PHP Coding Help
Thanks, mate! I appreciate it very much. Now, I just have to understand it. -
How do You Echo a Different List Every Day, Automatically?
Fluoresce replied to Fluoresce's topic in PHP Coding Help
Sure. It's like this: CREATE TABLE `featuretbl` ( `featuretblid` tinyint(1) NOT NULL UNSIGNED AUTO_INCREMENT, `featuredvid` tinyint(4) NOT NULL UNSIGNED, PRIMARY KEY (`featureid`) ) Surely, there's a way of optimising this: // Update feature table with new video IDs $sql = "UPDATE `featuretbl` SET `featuredvid` = $randid1 WHERE `featuretblid` = 1"; mysql_query($sql, $conn) or die(mysql_error()); $sql = "UPDATE `featuretbl` SET `featuredvid` = $randid2 WHERE `featuretblid` = 2"; mysql_query($sql, $conn) or die(mysql_error()); $sql = "UPDATE `featuretbl` SET `featuredvid` = $randid3 WHERE `featuretblid` = 3"; mysql_query($sql, $conn) or die(mysql_error()); $sql = "UPDATE `featuretbl` SET `featuredvid` = $randid4 WHERE `featuretblid` = 4"; mysql_query($sql, $conn) or die(mysql_error()); $sql = "UPDATE `featuretbl` SET `featuredvid` = $randid5 WHERE `featuretblid` = 5"; mysql_query($sql, $conn) or die(mysql_error()); -
How do You Echo a Different List Every Day, Automatically?
Fluoresce replied to Fluoresce's topic in PHP Coding Help
Thanks for your help, guys. Okay, here's what I've got so far. Will it work (I can't check it right now)? How could I improve it? 1. Create a file called once-a-day.php, to run once a day, with this code: <?php // Connect to database $conn = mysql_connect("localhost","", "") or die(mysql_error()); mysql_select_db("database"); // Find number of records $sql = "SELECT MAX(id) AS max FROM `video_tbl`"; $maxid = mysql_query($sql, $conn) or die(mysql_error()); $row = mysql_fetch_array($maxid); $largestNum = $row['max']; // Generate 5 different random video IDs $arr = array(); while(count($arr) < 5) { $x = mt_rand(0, $largestNum); if(!in_array($x, $arr)) { $arr[] = $x; } } $randid1 = $arr[0]; $randid2 = $arr[1]; $randid3 = $arr[2]; $randid4 = $arr[3]; $randid5 = $arr[4]; // Update feature table with new video IDs $sql = "UPDATE `featuretbl` SET `featuredvid` = $randid1 WHERE `featuretblid` = 1"; mysql_query($sql, $conn) or die(mysql_error()); $sql = "UPDATE `featuretbl` SET `featuredvid` = $randid2 WHERE `featuretblid` = 2"; mysql_query($sql, $conn) or die(mysql_error()); $sql = "UPDATE `featuretbl` SET `featuredvid` = $randid3 WHERE `featuretblid` = 3"; mysql_query($sql, $conn) or die(mysql_error()); $sql = "UPDATE `featuretbl` SET `featuredvid` = $randid4 WHERE `featuretblid` = 4"; mysql_query($sql, $conn) or die(mysql_error()); $sql = "UPDATE `featuretbl` SET `featuredvid` = $randid5 WHERE `featuretblid` = 5"; mysql_query($sql, $conn) or die(mysql_error()); ?> 2. On my home page, where I want the featured videos to appear, have something like this: <?php $conn = mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db(""); $sql = "SELECT `featuredvid` FROM `featuretbl`"; $results = mysql_query($sql, $conn) or die(mysql_error()); $arr = array(); while($row = mysql_fetch_assoc($results)) { $arr[] = $row['featuredvid']; } $randid1 = $arr[0]; $randid2 = $arr[1]; $randid3 = $arr[2]; $randid4 = $arr[3]; $randid5 = $arr[4]; // Select and print videos $sql = "SELECT `vid` FROM `video_tbl` WHERE (id = $randid1 OR id = $randid2 OR id = $randid3 OR id = $randid4 OR id $randid5)"; $results = mysql_query($sql, $conn) or die(mysql_error()); while($row = mysql_fetch_array($results)) { print $row['vid'] . "<br />"; } ?> -
How do You Echo a Different List Every Day, Automatically?
Fluoresce replied to Fluoresce's topic in PHP Coding Help
Thanks, requinix, but I'm not sure I understood all of that. My database currently has no gaps. In more detail, here's what I want to do: Every day, I want my home page to display 3 featured videos. The same 3 videos have to be displayed all day. Then, the next day, I want 3 new videos to be displayed. Below is what I've got so far. Remember, I'm a complete novice, so it probably looks ridiculous to many of you! You won't be surprised to hear that it doesn't work. It always prints 3 different records. <?php // Select and print 3 records if $todaysdate is not today's actual date if($todaysdate != date("d-m-y")) { $todaysdate = date("d-m-y"); // Connect to database $conn = mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("database"); // Find number of records $maxid = mysql_query("SELECT MAX(id) AS max FROM `vids`"); $row = mysql_fetch_array($maxid); $largestNum = $row['max']; // Generate 3 different random IDs $arr = array(); while(count($arr) < 3) { $x = mt_rand(0, $largestNum); if (!in_array($x, $arr)) { $arr[] = $x; } } $randid1 = $arr[0]; $randid2 = $arr[1]; $randid3 = $arr[2]; // Select and print results $sql = "SELECT record FROM `vids` WHERE (id=$randid1 OR id=$randid2 OR id=$randid3)"; $results = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($results)) { print $row['record'] . "<br />"; } } else { $sql = "SELECT record FROM `vids` WHERE (id=$randid1 OR id=$randid2 OR id=$randid3)"; $results = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($results)) { print $row['record'] . "<br />"; } } ?> -
I want a "Featured Videos" list on my home page that shows a different list of videos, randomly selected from a database, every day. How can this be done? As a PHP novice, I don't even know where to begin! I'm not asking for you guys to do this for me. I want to learn how to do things like this for myself. All I'm asking for is a push in the right direction. As always, I appreciate you guys' help. I've learnt loads here.