Jump to content

Recommended Posts

I operate several 'fanlistings' where people who are fans of things can join and be listed among other fans. It's powered by the Enthusiast script. I recently switched hosts (to DreamHost) - and before this I wasn't having any issues. Someone told me that my join form was giving them trouble and I tested it out and am getting this error:

Warning: preg_match() expects parameter 2 to be string, array given in /home/fatedus/fatedus/loved/admin/show_join.php on line 141

This is line 141 of show_join.php:

if( $_POST && preg_match( $matchstring, $_POST ) ) 

Here is a link to one of my fanlisting's join page: http://odin.fated.us/join.php

 

And here is a link to the Enthusiast script for those unfamiliar with it: http://scripts.indisguise.org/

 

Any help would be greatly appreciated, I know extremely little about PHP.

Link to comment
https://forums.phpfreaks.com/topic/288882-enthusiast-join-form-error/
Share on other sites

The error was probably always there, it was likely just hidden in your previous hosting environment.

 

As the error suggests, the second argument for preg_match() needs to be a string. You're passing $_POST which is an array. Is there a specific variable in the POST array that you want to use for the match? If so, you could modify the code to something like this:

if( $_POST && preg_match( $matchstring, $_POST['valueToCheck'] ) )

If you're looking to check all variables in the POST array, you could look into using a loop.

The error is fairly simple and clear. Here is the manual page for http://us3.php.net/preg_match.

 

The line of code is passing $_POST as the 2nd param to preg_match and $_POST is a super global array. As the warning explains, the parameter has to be a string.

Whoa. mac_gyver was right, I have no clue how that happened. Thank you so much, I never would have even known to look for that.

 

After replacing show_join.php with a brand new show_join.php (with the correct line) I'm still getting this error when I try to join:

Deprecated: Function ereg() is deprecated in /home/fatedus/fatedus/loved/admin/show_join.php on line 141

And yeah, of course, this is the new line 141:

 if( $_POST['email'] && ereg( $matchstring, $_POST['email'] ) )

Apparently the join form works 'cause I just got the confirmation e-mail that I joined.. I'm just also getting that error above on the confirmation page right after I submit the form.

Hey, I told you in the first post that I know almost nothing about PHP. I wasn't joking. :P

 

I replaced the line as you instructed, and am now getting this error and am not being allowed to submit the form (will be going back to the old line now 'cause at least it let people join): 

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in /home/fatedus/fatedus/loved/admin/show_join.php on line 141
Edited by Ashes

Hope this is enough, this looks like a 'section' to me.

   $matchstring = "^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+" .
      "@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$";
   if( $_POST['email'] && ereg( $matchstring, $_POST['email'] ) )
      $email = clean( $_POST['email'] );
   else
      $messages['email'] = 'You must enter a valid email address.';

I figured it out on my own, changed it to this and everything is working smoothly:

   $matchstring = "/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+" .
      "@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/";
   if( $_POST['email'] && preg_match( $matchstring, $_POST['email'] ) )

Thanks everyone for your help, it was very much appreciated!!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.