User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,596 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,650 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 241 | Replies: 2 | Solved
Reply
Join Date: May 2008
Posts: 46
Reputation: antwan1986 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
antwan1986's Avatar
antwan1986 antwan1986 is offline Offline
Light Poster

Hopefully a straightforward PHP/MySQL question

  #1  
May 8th, 2008
Hi everyone and thanks for reading!

I have a MySQL database with a table called "lessons". Inside lessons there are about six or seven fields holding information about piano lessons. The table looks like this:

vid  	int(10) (Primary Key)
title 	varchar(50)
date 	date
teaser 	varchar(500)
description 	varchar(2000)
vurl 	varchar(50)
extra 	varchar(1000)

All I'm wanting to do is retrieve these values and place them where I'd like, so I know the code to do that through the SELECT statement WHERE vid = and then the paramater I pass in the URL.

At the moment I only have one record, so the vid=1 and this works fine. What I'm wanting to do is make a bit of PHP that stops people trying to access records that don't exist, like vid=33 and so on. At the moment it loads the page and displays no values (because there is no record 33!) but i'd rather it realised there was no record 33 and brought up a message saying sorry there is no such record. I've made one that catches if they've removed the ?vid like so:

$vid = $_GET['vid'];
if (!$vid) { echo "<h2>We've Encountered A Problem</h2>\n"; };
die;

Can anyone help me catch these records that don't exist?

Anthony
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 37
Reputation: robothy is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
robothy robothy is offline Offline
Light Poster

Re: Hopefully a straightforward PHP/MySQL question

  #2  
May 8th, 2008
Hey,

If you run the SQL select query to find a vid record, if it returns no rows, which you can find using mysql_num_rows(), display the error message.

R.
Reply With Quote  
Join Date: May 2008
Posts: 46
Reputation: antwan1986 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
antwan1986's Avatar
antwan1986 antwan1986 is offline Offline
Light Poster

Re: Hopefully a straightforward PHP/MySQL question

  #3  
May 8th, 2008
Originally Posted by robothy View Post
Hey,

If you run the SQL select query to find a vid record, if it returns no rows, which you can find using mysql_num_rows(), display the error message.

R.


Hi and thanks for your quick reply. I looked that function and came up with the following, which works brilliantly.

if (mysql_num_rows($result) == 0) { die("Uh-oh.."); };

Thank you very much, you're a life saver.

Anthony
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:44 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC