473,434 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

Re: Building a blog from scratch using PHP

On 2008-07-11 15:21:31 +0100, "Peter D." <pe*****@gmail.comsaid:
On Jul 10, 3:00*pm, JT <tornet...@gmail.comwrote:
><SNIP>

What I want is to do the URL validation like I just describe, but I
also want it to compare whether the input matches an actual database
entry, and if not return a 404 error. *Right now, for some reason if
you type inhttp://www.myblog.com/blog/viewentry.php?id=500, and I
only have 3 rows in my database, it doesnt return an error, it
displays the viewentry page thats blank with my post footer displaying
a bogus date.

<SNIP>

Thanks
JT

Why don't you just validate the information you get back from the
database. Or do a mysql_num_rows and if it returns 0 then there are no
rows matching your query. if mysql_num_rows == 0 go back to main page.

Maybe?
That'd be the correct way of doing it.
You could even direct to the 404 page if the query result is empty.

Condiser changing:
if(is_numeric($_GET['id']) == FALSE) {
$error = 1;
}
if($error == 1) {
header("Location: " . $config_basedir);
}
else {
$validentry = $_GET['id'];
}

to:
if(is_numeric($_GET['id']) == FALSE) {
header("Location: " . $config_basedir);
}
else {
$validentry = $_GET['id'];
}
--
../Sven

Jul 12 '08 #1
2 1260
JT
On Jul 12, 6:17*am, Sven wrote:
On 2008-07-11 15:21:31 +0100, "Peter D." <pete...@gmail.comsaid:
On Jul 10, 3:00*pm, JT <tornet...@gmail.comwrote:
<SNIP>
What I want is to do the URL validation like I just describe, but I
also want it to compare whether the input matches an actual database
entry, and if not return a 404 error. *Right now, for some reason if
you type inhttp://www.myblog.com/blog/viewentry.php?id=500, and I
only have 3 rows in my database, it doesnt return an error, it
displays the viewentry page thats blank with my post footer displaying
a bogus date.
<SNIP>
Thanks
JT
Why don't you just validate the information you get back from the
database. Or do a mysql_num_rows and if it returns 0 then there are no
rows matching your query. if mysql_num_rows == 0 go back to main page.
Maybe?

That'd be the correct way of doing it.
You could even direct to the 404 page if the query result is empty.

Condiser changing:
* * * * * * * * if(is_numeric($_GET['id']) == FALSE) {
* * * * * * * * * * * * $error = 1;
* * * * * * * * }
* * * * * * * * if($error == 1) {
* * * * * * * * * * * * header("Location: " . $config_basedir);
* * * * * * * * }
* * * * * * * * else {
* * * * * * * * * * * * $validentry = $_GET['id'];
* * * * * * * * }

to:
* * * * * * * * if(is_numeric($_GET['id']) == FALSE) {
* * * * * * * * * * * * header("Location: " . $config_basedir);
* * * * * * * * }
* * * * * * * * else {
* * * * * * * * * * * * $validentry = $_GET['id'];
* * * * * * * * }

--
./Sven
Thanks everyone, I will try your suggestions using mysql_num_rows, and
I will also remove the $error variable. I'll let you know how it
turns out as soon as I get time to update my code.

JT
Jul 12 '08 #2
<Svenposted:
: Consider:
:
: if(is_numeric($_GET['id']) == FALSE) {
: header("Location: " . $config_basedir);
: } else {
: $validentry = $_GET['id'];
: }
:

Just curious, should that code read as:

if(is_numeric($_GET['id']) === FALSE) {
header("Location: " . $config_basedir);
exit();
} else {
$validentry = $_GET['id'];
}

Because what if id = 0. And should one not ALWAYS employ an
exit(); statement after a redirection? Is it now safe to use
redirection without the exit();?

--
JC
Natural Cure For Pink-Eye (Conjunctivitis)
http://www.associatedcontent.com/art...nctivitis.html
Jul 17 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: FinallyInSeattle | last post by:
I have an old product that generates a Word document using Word Automation (tables, pictures, etc). The execution speed is quite slow and I'm finally at the point where I can tell my customers...
3
by: Leith Bade | last post by:
I have been trying to use the new Visual C++ Toolkit 2003 with the VC6 IDE I set up the executable, inlcude, and library directories to point to the new compilers I had to fix a few errors in the...
4
by: =?Utf-8?B?Uml6d2Fu?= | last post by:
In the system I am working on, there are 3 credit cards: Visa, MasterCard and AmericanExpress. On the database side I have one table: credit_card CREATE TABLE credit_card ( credit_card_id int...
0
by: jephperro | last post by:
Hi Everyone, I'm in a dilly of a pickle, and am hoping someone can give me some advice. I've never done any blogging before, and now my boss wants me to create a web site where users can...
3
Plater
by: Plater | last post by:
Well, I'm not sure where to put this, but I figured people using ajax are more likely to run into these issues. I have been building my own webserver (don't ask, just trust me when I say I have...
0
by: waggledance | last post by:
I was wondering if anyone here might be able to offer me some advice for someone who can only use Macromedia Dreamweaver MX. I am (clearly!) a web design novice so apologies in advance if this is a...
4
by: =?Utf-8?B?SmVmZkRvdE5ldA==?= | last post by:
I’m interested in setting up an Intranet blog/forum application for work. The idea is to have people in the office blog about projects they are working on and problems they are facing. We will...
5
by: Tim Royal | last post by:
I used WordPress for a prior blog, but now have my website on ASP.Net 2.0 using MS SQL Server. I'd like to actually have an equivalent blog (easy to set up, easy to add entries to for the family)....
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.