EREG to PREG_MATCH Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

EREG to PREG_MATCH Error

Post by gazzieh »

Hi

I have built a system on my localhost, which is running PHP 5.2.1 and mySQL 5.0.33. I have used the following code:

Code: Select all

function validateTextOnly($theinput,$description = '') {
   $result = ereg ("^[A-Za-z0-9\ ]+$", $theinput );
      if ($result) { return true; }
      else {
         $this->errors[] = $description;
	 return false; }}
I have uploaded the site (that works locally) and hit error after error. The first one I realised is that my local mySQL converted my passwords using the PASSWORD() parameter and resulted in letters and numbers. However, my hosted area has the newer PASSWORD() system that adds a * to the front.

I added * to my array for EREG but this still failed. I then realised that EREG has gone and that I should now use PREG_MATCH. However, I tried this:

Code: Select all

$result = preg_match ("/^[A-Za-z0-9\ ]+$*/", $theinput );
This fails everytime, so what am I doing wrong?

My hosted system uses PHP 5.2.13 and mySQL 5.0.90.

***** EDIT ******

Okay, I now realise that I should have used \* rather than * to rule out it's use as a command. However, local is logging in, remote site is not. Any ideas?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: EREG to PREG_MATCH Error

Post by requinix »

1. Are you sure the only difference between the two is the added *?
2. What's the rest of your code? Because if there's a problem and it's not with the validator then it must be somewhere else.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: EREG to PREG_MATCH Error

Post by cpetercarter »

Code: Select all

$result = preg_match ("/^[A-Za-z0-9 \*]+$/", $theinput );
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Re: EREG to PREG_MATCH Error

Post by gazzieh »

tasairis wrote:1. Are you sure the only difference between the two is the added *?
2. What's the rest of your code? Because if there's a problem and it's not with the validator then it must be somewhere else.
Thanks for both the replies. I did use the suggested code but still not working.

I have used the same file as I have locally but only changed the ereg to preg statement. Local works fine, remote does not.

No error file about connecting to the database and the home page loads fine so this is an error on validation. As soon as I log in the system takes me to the error in logging in page (locally it takes me to the logged in homepage).

The total code for this section of the validation is as below. I am assuming further deprecation and any help given will be gratefully received:

Code: Select all

// Validate text only
		function validateTextOnly($theinput,$description = '')
			{
			$result = ereg ("^[A-Za-z0-9\ ]+$", $theinput );  // This is deprecated. New preg_match statement used here on remote page
			if ($result)
				{
				return true;
				}
			else
				{
				$this->errors[] = $description;
				return false; 
				}
			}
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: EREG to PREG_MATCH Error

Post by AbraCadaver »

Do this on both local and remote:

Code: Select all

echo get_magic_quotes_gpc();
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Re: EREG to PREG_MATCH Error

Post by gazzieh »

AbraCadaver wrote:Do this on both local and remote:

Code: Select all

echo get_magic_quotes_gpc();
Okay, and got 11 on both occasions (which is what I would expect, since I run the validation twice).

Therefore, magic quotes are on in both cases.
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Re: EREG to PREG_MATCH Error

Post by gazzieh »

The fault lay in the fact that the SQL security system has changed. The new SQL PASSWORD() function checks a 41 character code yet the older style was only 20 characters long. Therefore my system was not able to confirm the password since the stored values were truncated. DOH!

All solved now.
Post Reply