Go Back   Cyber Tech Help Support Forums > Software > Web Development & Graphic Design

Notices

Reply
 
Topic Tools
  #1  
Old August 1st, 2006, 04:19 AM
crashnet crashnet is offline
Member
 
Join Date: May 2004
Posts: 45
PHP: EREG() function and databases

Many are probably familiar with the ereg() function in php:

Example:
PHP Code:
ereg("^word$|^help$|^test$|^keys$"$_GET['$size']) 
Now here's my problem. I am checking for image sizes that are admin defined and stored in a table in a database. $size is the size the visitor selects when searching for an image, but because they are admin defined sizes, I don't know what they are nor do I know how many of them there are. How would I go about pulling the sizes from the database so I can check $size to be sure it is one of the available sizes?

I hope this makes sense. It was the best way I could describe my situation.
Reply With Quote
  #2  
Old August 1st, 2006, 11:10 AM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,042
Blog Entries: 1
Create a recordset first to pull the size table from the database. You can then loop through it or create an array or function to compare sizes.
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
  #3  
Old August 2nd, 2006, 08:40 PM
crashnet crashnet is offline
Member
 
Join Date: May 2004
Posts: 45
Thank you Degs for your response. While playing with this, I came up with another question. Is there really even a need to check that the value of $size is equal to one of the sizes in the database? $size gets its value from a dropdown menu, and that menu is populated by the same table in the database used to check it, but I have seen in other examples in the past that variables that get their values from select menus in a form are still checked, even though the programmer, the administrator, and the user all know that the contents of that variable is going to be one of the options.

This is part of a search script that will be used very frequently, so I'm going for as little code as possible to save resources and increase speed.

Thanks again!
Reply With Quote
  #4  
Old August 3rd, 2006, 11:16 AM
degsy's Avatar
degsy degsy is offline
Cyber Tech Help Moderator
 
Join Date: Jul 2001
Location: North-East, UK
Posts: 22,042
Blog Entries: 1
If you know the values then you don't neccessarilly have to check them. The problem is if a user saves the page to their drive and edit's it and changes the values. That is why you should have validation just incase.
__________________
Cheers,
Degs

Please post back with your results
CTH Terms of Use

CTH Subscriptions :: Adaware Guide :: HijackThis
Reply With Quote
  #5  
Old August 5th, 2006, 06:22 PM
crashnet crashnet is offline
Member
 
Join Date: May 2004
Posts: 45
Hmm...never would have thought of that. Thanks Degsy.
Reply With Quote
Reply

Bookmarks

Topic Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:41 AM.

[ RSS ]