FORUM HOME | WHUK BLOG   
WEB HOSTING UK AFFORDABLE WEBSITE HOSTING SERVICES IN UNITED KINGDOM
PHP LINUX SHARED HOSTING WINDOWS ASP.NET HOSTING PACKAGES
ECOMMERCE HOSTING ASP MSSQL MS ACCESS ODBC FRONTPAGE HOSTING
CPANEL WHM FANTASTICO RESELLER DEDICATED SERVER WEB HOSTING
CHEAP PLESK CPANEL HTML MYSQL BEST UK VPS HOSTING COMPANY
CHEAP RELIABLE UK HOSTING PROVIDER SINCE 2001
MANAGED WEB HOSTING SERVICE
AFFORDABLE WEBSITE HOSTING SERVICES IN UNITED KINGDOM

Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum » Technical Support » MySQL Hosting

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 03-03-09, 09:00 AM
perplexed's Avatar
Member
 
Join Date: Jan 2009
Posts: 41
Default 'select all' selects all NOOOOOOO!

I'm still having a mountain of baffling problems getting basic and simple scripts and queries to work with my new host here on WHUK.

These scripts have worker perfectly (and also instantly upon creation) with my previous hosts servers for the best part of a decade. WHUK are using the same MySql version as the scripts were coded.

Please can someone tell me, if it is me at fault, what is wrong with the following query. I wish to select all COLUMNS not all RECORDS in the database - which is exactly what it spews out.

Surely i don't have to replace the '*' with the name of every single column?. I'm using the same version and '*' is a perfectly valid shorthand to use.

PHP Code:
$sql=stripslashes ("SELECT * FROM table_name WHERE '$a' LIKE '%$b%' ORDER BY '$c'"); 

Last edited by perplexed; 03-03-09 at 09:02 AM.
Reply With Quote

  #2 (permalink)  
Old 03-03-09, 12:19 PM
Senior Member
 
Join Date: Jan 2007
Location: Dorset
Posts: 1,089
Default

I don't see anything wrong with your query.
I can only assume that your problem is with $b.
If $b is empty then it would explain why it prints all the records as the % relates to anything.

Can you give an example of what $b is? and were register_globals on or off with your previous host, and this one.
__________________
West Dorset Community
Reply With Quote

  #3 (permalink)  
Old 03-03-09, 02:31 PM
perplexed's Avatar
Member
 
Join Date: Jan 2009
Posts: 41
Default

Quote:
Originally Posted by jon123 View Post
I don't see anything wrong with your query.
I can only assume that your problem is with $b.
If $b is empty then it would explain why it prints all the records as the % relates to anything.

Can you give an example of what $b is? and were register_globals on or off with your previous host, and this one.
Been a long time since had to compile php and MySql scripts for a specific purpose (as ony needed to do it the initial time and leave them running for years).....but....mention of register_globals will be well worth my checking out. Lycos has closed down and wiped it's servers clean, however, i'm sure i printed out the variables and settings for their MySql.

$a, $b and $c are web page form fields. It would read, as an example, select 'songs' from 'database' where 'title' like '%love%' order by 'artist'.

The inclusion of the wildcards '%' mean that it would select all coulumns in a record row containing song titles such as 'I Love You' 'Do You Love Me' etc.

The actual web page contains various types of queries using varying number of fields as one wishes or needs and with or without the wildcard option.

Last edited by perplexed; 03-03-09 at 02:33 PM.
Reply With Quote

  #4 (permalink)  
Old 05-03-09, 11:13 AM
black-dog's Avatar
Senior Member
 
Join Date: May 2008
Location: Newcastle under Lyme
Posts: 199
Send a message via Yahoo to black-dog
Default

Quote:
Originally Posted by perplexed View Post
I'm still having a mountain of baffling problems getting basic and simple scripts and queries to work with my new host here on WHUK.

These scripts have worker perfectly (and also instantly upon creation) with my previous hosts servers for the best part of a decade. WHUK are using the same MySql version as the scripts were coded.

Please can someone tell me, if it is me at fault, what is wrong with the following query. I wish to select all COLUMNS not all RECORDS in the database - which is exactly what it spews out.

Surely i don't have to replace the '*' with the name of every single column?. I'm using the same version and '*' is a perfectly valid shorthand to use.

PHP Code:
$sql=stripslashes ("SELECT * FROM table_name WHERE '$a' LIKE '%$b%' ORDER BY '$c'"); 

As others have said, it is most likely a register globals issue.

Add the following line to your code

echo $sql;

and see if the query actually contains what you think it contains.

All modern installations will have register globals disabled. This is a Good Thing but may need some tweaking of legacy code.

The code looks like it could be potentially very insecure. Assuming the variables are coming from a POSTed form you should have

PHP Code:
$a=mysql_real_escape_string($_POST['a']);
$b=mysql_real_escape_string($_POST['b']);
$c=mysql_real_escape_string($_POST['c']);

$sql="SELECT * FROM table_name WHERE '$a' LIKE '%$b%' ORDER BY '$c'"
You may not need the stripslashes.
__________________
black-dog
4theweb.co.uk Web stuff
slipperyhill.co.uk Band

Last edited by black-dog; 05-03-09 at 11:17 AM.
Reply With Quote

  #5 (permalink)  
Old 06-03-09, 04:29 AM
perplexed's Avatar
Member
 
Join Date: Jan 2009
Posts: 41
Default

Result from adding the echo $sql shows that all three of the form fields are not receiving the values. This means the query reads simply as 'select all' !

SELECT * FROM table WHERE '' LIKE '%%' ORDER BY ''


Incidentally, i've never seen the mysql_real_escape_string mentioned before. Again that shows how long ago it was since i wrote the code. The database whilst being hosted on my website and accessed via a webpage is just for personal use. As a result one needs a username and password to access the search page.

Last edited by perplexed; 06-03-09 at 04:49 AM.
Reply With Quote

  #6 (permalink)  
Old 06-03-09, 05:12 AM
perplexed's Avatar
Member
 
Join Date: Jan 2009
Posts: 41
Default

Too be honest i've just spent an hour trying a myriad of ways to get this database working and i despair. It's becoming the most frustrating, enraging and infuriating task.

I've looked under 'Server variables and settings' and in a very long list can find no mention whatsoever of 'global_variables'...so are they on or off? haven't got a clue and before i smash my computer against the wall...i'm walking away and will try again tomorrow.

Final annoying straw...par for the course i guess. I just went to add the above paragraphs in an edit...and as always when one presses save you are told you don't have permisiion to do so..refresh the page and login again. The backbreaker being, after doing that the edit option has gone and i can only 'add reply'....nice!
Reply With Quote

  #7 (permalink)  
Old 06-03-09, 08:10 AM
Member
 
Join Date: Nov 2007
Posts: 42
Default

Quote:
Originally Posted by perplexed View Post
Too be honest i've just spent an hour trying a myriad of ways to get this database working and i despair. It's becoming the most frustrating, enraging and infuriating task.

I've looked under 'Server variables and settings' and in a very long list can find no mention whatsoever of 'global_variables'...so are they on or off? haven't got a clue and before i smash my computer against the wall...i'm walking away and will try again tomorrow.

Final annoying straw...par for the course i guess. I just went to add the above paragraphs in an edit...and as always when one presses save you are told you don't have permisiion to do so..refresh the page and login again. The backbreaker being, after doing that the edit option has gone and i can only 'add reply'....nice!
The php.ini variable is register globals, I recommend you don't touch it.

I am assuming your scripts use the GET method to parse the data to your variables.
All you need to do is add is $a = $_GET['a']; $b = $_GET['b']; $c = $_GET['c']; etc.
Reply With Quote

  #8 (permalink)  
Old 06-03-09, 09:30 AM
black-dog's Avatar
Senior Member
 
Join Date: May 2008
Location: Newcastle under Lyme
Posts: 199
Send a message via Yahoo to black-dog
Default

Quote:
Originally Posted by perplexed View Post
Result from adding the echo $sql shows that all three of the form fields are not receiving the values. This means the query reads simply as 'select all' !

SELECT * FROM table WHERE '' LIKE '%%' ORDER BY ''


Incidentally, i've never seen the mysql_real_escape_string mentioned before. Again that shows how long ago it was since i wrote the code. The database whilst being hosted on my website and accessed via a webpage is just for personal use. As a result one needs a username and password to access the search page.
Fair enough, but I would recommend the use of mysql_real_escape_string in ALL cases of user supplied data, password protected or not. It's just a good habit to get into and helps prevent sql injection (Google it for more info).
__________________
black-dog
4theweb.co.uk Web stuff
slipperyhill.co.uk Band

Last edited by black-dog; 06-03-09 at 09:42 AM.
Reply With Quote

  #9 (permalink)  
Old 06-03-09, 09:40 AM
black-dog's Avatar
Senior Member
 
Join Date: May 2008
Location: Newcastle under Lyme
Posts: 199
Send a message via Yahoo to black-dog
Default

Quote:
Originally Posted by perplexed View Post
Too be honest i've just spent an hour trying a myriad of ways to get this database working and i despair. It's becoming the most frustrating, enraging and infuriating task.

I've looked under 'Server variables and settings' and in a very long list can find no mention whatsoever of 'global_variables'...so are they on or off? haven't got a clue and before i smash my computer against the wall...i'm walking away and will try again tomorrow.
OK, calm down and take a deep breath. The first thing is not to blame the hosting, all installations will be like this soon, it's just the PHP upgrade.

Your variables are not getting to your database query, that much is obvious from the echo $sql statement.

In the past, register_globals was on by default. This means, among other things that if you write
Code:
http://www.example.com?myvariable=foo&myothervariable=bar
then the two variables $myvariable and $myothervariable will be available in your script.This is a potential security risk in badly written scripts. (there is loads on this on the web so I won't explain further here) As of PHP 5 register_globals is off by default and scripts relying on it have to be rewritten. That's just fact, deal with it, we all have to.

So, how are your variables getting into the query?

If they are coming from a form using the POST method then the code I posted earlier will work. If they are coming from the URL as above, replace POST with GET (as Scottie has mentioned) If you are not sure if it is GET or POST then do

PHP Code:
$a=mysql_real_escape_string($_REQUEST['a']);
$b=mysql_real_escape_string($_REQUEST['b']);
$c=mysql_real_escape_string($_REQUEST['c']); 
Before the $sql=... bit.


If that fails, tell me where your variables are coming from and I'll help you get it to work.
__________________
black-dog
4theweb.co.uk Web stuff
slipperyhill.co.uk Band

Last edited by black-dog; 06-03-09 at 09:51 AM.
Reply With Quote

  #10 (permalink)  
Old 06-03-09, 01:32 PM
perplexed's Avatar
Member
 
Join Date: Jan 2009
Posts: 41
Default

Black-dog first of all most importantly many thanks for the replies. I was fearing that my requests for help would have exceeded peoples patience limits.

One thing i should make clear is that i am not blaming my new hosts for my long serving scripts falling flat.

Your comment about the php upgrade is enlightning. My Lycos one (i'll check in detail later) was a very similar version i am sure, however, maybe it was slightly one update back?.

I'll address the queries that you need answering tonight or tomorrow - i'm just off out right now.

I was going to post the form scripts and complete script for the form action but thought it would either bore/annoy you or take up to much space on the forum. Having said that they are very small.

When i was trying the code snippet you provided i did indeed place it ahead of the mysql query. As to why it didn't work, i will try again when in a calmer frame of mind lol.

I will indeed change all my scripts across my site to use the (new to me) 'mysql_real_escape_string'. First of all i need to get the database running again. It's not accessible to others anyway, as only myself has a username and password for it.

Also, scottie mentioning php.ini now reminds me my parameter print out was obtained from the php documentation. I was searching for it in the mysql docs.

I apologise if this is all now more fitting in the php forum???, but, i find it impossible to separate php and mysql as they 99% of the time go hand in hand. I didn't wish to duplicate my post in both forums. Initially, i presumed the fault lay in the syntax of my mysql scripting.
Reply With Quote

  #11 (permalink)  
Old 06-03-09, 02:52 PM
black-dog's Avatar
Senior Member
 
Join Date: May 2008
Location: Newcastle under Lyme
Posts: 199
Send a message via Yahoo to black-dog
Default

Quote:
Originally Posted by perplexed View Post
Black-dog first of all most importantly many thanks for the replies. I was fearing that my requests for help would have exceeded peoples patience limits.
I'm a coder - I have endless patience...

Quote:
Originally Posted by perplexed View Post
was going to post the form scripts and complete script for the form action but thought it would either bore/annoy you or take up to much space on the forum. Having said that they are very small.
Usual advice is to cut down scripts to the minimum that still shows the error

Quote:
Originally Posted by perplexed View Post
I will indeed change all my scripts across my site to use the (new to me) 'mysql_real_escape_string'. First of all i need to get the database running again. It's not accessible to others anyway, as only myself has a username and password for it.
mysql_real_escape_string() won't solve this problem, but it's good practice to sanitise any user input, even if it is password protected.

Quote:
Originally Posted by perplexed View Post
Also, scottie mentioning php.ini now reminds me my parameter print out was obtained from the php documentation. I was searching for it in the mysql docs.
You really don't need to be making any changes here, even if you can.

Quote:
Originally Posted by perplexed View Post
I apologise if this is all now more fitting in the php forum???
Oh we'll probably let you off...
__________________
black-dog
4theweb.co.uk Web stuff
slipperyhill.co.uk Band
Reply With Quote

  #12 (permalink)  
Old 16-05-09, 10:21 PM
perplexed's Avatar
Member
 
Join Date: Jan 2009
Posts: 41
Default

Quote:
Originally Posted by black-dog View Post
Your variables are not getting to your database query, that much is obvious from the echo $sql statement.

In the past, register_globals was on by default. This means, among other things that if you write
Code:
http://www.example.com?myvariable=foo&myothervariable=bar
then the two variables $myvariable and $myothervariable will be available in your script.This is a potential security risk in badly written scripts. (there is loads on this on the web so I won't explain further here) As of PHP 5 register_globals is off by default and scripts relying on it have to be rewritten. That's just fact, deal with it, we all have to.

PHP Code:
$a=mysql_real_escape_string($_REQUEST['a']);
$b=mysql_real_escape_string($_REQUEST['b']);
$c=mysql_real_escape_string($_REQUEST['c']); 
Before the $sql=... bit.


If that fails, tell me where your variables are coming from and I'll help you get it to work.
OK after giving up on my whole website in despair for a couple of months (because i can't get simple scripts and webpages displaying that have worked elsewhere for years) i'm trying to get the time to have another stab.

My query is POSTED from the webpage form. I added the php code you suggested.

What happens now is instead of the whole database table displaying, and not just the selected rows, none of it displays.

However, a possible step nearer to solving the problem is that the MySql query now contains the fields entered into the search form - previously the fields were showing empty.

So whilst not displaying the results yet, the query shows up as;

Select * from database_name where artist like 'beatles' song like '%love%' order by 'folder'

This should normally display all songs by the beatles with the word 'love' anywhere in the title. (folder refers to the physcal folder i have music scores stored in)

Do you think the problem now moves on to the target (of the POST command) script of the query page? If so i can supply the script for that, it is only a few lines.
Reply With Quote

  #13 (permalink)  
Old 17-05-09, 07:30 AM
black-dog's Avatar
Senior Member
 
Join Date: May 2008
Location: Newcastle under Lyme
Posts: 199
Send a message via Yahoo to black-dog
Default

Quote:
Originally Posted by perplexed View Post

So whilst not displaying the results yet, the query shows up as;

Select * from database_name where artist like 'beatles' song like '%love%' order by 'folder'

This should normally display all songs by the beatles with the word 'love' anywhere in the title. (folder refers to the physcal folder i have music scores stored in)

Do you think the problem now moves on to the target (of the POST command) script of the query page? If so i can supply the script for that, it is only a few lines.
Not sure what you mean by 'moves on'. Your query is wrong for a start. It should be Select * from database_name where artist like 'beatles' AND song like '%love%' order by 'folder' The AND is missing. How is the query being constructed? Is error reporting on (if not, add the line error_reporting(E_ALL); at the top of your script) and have you any undefined variable errors?
__________________
black-dog
4theweb.co.uk Web stuff
slipperyhill.co.uk Band

Last edited by black-dog; 17-05-09 at 07:53 AM.
Reply With Quote

  #14 (permalink)  
Old 17-05-09, 08:49 PM
perplexed's Avatar
Member
 
Join Date: Jan 2009
Posts: 41
Default

Hi black-dog, i was hoping you were still around these forums lol.

First of all i must clarify that 'AND' is included in the query, i had just made a typo when posting it here.

Secondly, wow i like the error_reporting(E_ALL) function, i think i'll be adding that to every single script i ever write.

It threw up the following error,

Fatal error: Function name must be a string in E:\inetpub\vhosts\website.com\subdomains\xxxx\http docs\file.php on line 21

Rather than come running straight back here, i did a little research on Google. Someone with a similar problem was told that

$_POST is an array not a function, access its elements with [] not ()

Now the nearest line to 21 is,

Code:
$sql=stripslashes ("SELECT * FROM database_name WHERE '$a' LIKE '%$b%' ORDER BY '$c'");
I do know that when a line is quoted as a php error it can actually be in the previous line/s. Therefore, i'll mention the segment above which is,

Code:
$a=mysql_real_escape_string($_POST['a']);
$b=mysql_real_escape_string($_POST['b']);
$c=mysql_real_escape_string($_POST['c']);
Would you know if i should replace any of the curved brackets with square ones in any of the above?.

Only in the escape part, there are square brackets, although those are surrounded by circular ones. Alternatively is the fault with the select segment or the inclusion of stripslashes (which had to used on lycos).
Reply With Quote

  #15 (permalink)  
Old 17-05-09, 10:21 PM
black-dog's Avatar
Senior Member
 
Join Date: May 2008
Location: Newcastle under Lyme
Posts: 199
Send a message via Yahoo to black-dog
Default

Get rid of the stripslashes on line 21
__________________
black-dog
4theweb.co.uk Web stuff
slipperyhill.co.uk Band
Reply With Quote

Reply

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT. The time now is 04:47 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 2001-2009 Web Hosting UK. All rights reserved.
Web Hosting UK Forum





Site Map

Dedicated Servers
Dedicated Server Hosting

Load Balanced Server
Load Balancing Server

SEO Servers
SEO Server Hosting

VoIP Servers
Linux VoIP Servers

Cloud VPS Hosting
VMware Cloud VPS Hosting

VPS Hosting
Linux VPS Hosting

Windows VPS
Windows 2003 VPS

Hyper-V VPS Hosting
Windows 2008 VPS

cPanel Hosting
Shared Linux Hosting

Windows Hosting
Shared Windows Hosting

Coldfusion Hosting
Windows Coldfusion Hosting

cPanel Reseller Hosting
Shared Windows Hosting

Windows Reseller
Windows Reseller Hosting

Email Web Hosting
Email Hosting

Semi-Dedicated Server
Semi-Dedicated Hosting

Remote Backup Plans
Offsite Backup Service


cpanel hosting
Knowledgebase Articles

Pre-Sales Question
Web Hosting FAQ's

Dedicated Server
Dedicated Server FAQ's

Virtual Private Servers
VPS Hosting

PHP MySQL Hosting
cPanel Hosting

Windows Hosting
ASP MSSQL Hosting

Domain Name
Domain registration FAQ's

CMS Hosting
CMS Hosting FAQ's

Payment Gateways
Payment FAQ's


Support Tutorials

cPanel Tutorials
cPanel Flash Tutorials

Plesk Tutorials
Plesk Flash Tutorials

PhpMyadmin Tutorials
PhpMyadmin Flash Tutorials

Drupal Tutorials
Drupal Flash Tutorials

Mambo Tutorials
Mambo Flash Tutorials

Joomla Tutorials
Joomla Flash Tutorials

Wordpress Tutorials
Wordpress Flash Tutorials

Other Web Hosting Tutorials