Ashes Posted May 30, 2014 Share Posted May 30, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/288882-enthusiast-join-form-error/ Share on other sites More sharing options...
cyberRobot Posted May 31, 2014 Share Posted May 31, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/288882-enthusiast-join-form-error/#findComment-1481461 Share on other sites More sharing options...
gizmola Posted May 31, 2014 Share Posted May 31, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/288882-enthusiast-join-form-error/#findComment-1481465 Share on other sites More sharing options...
mac_gyver Posted May 31, 2014 Share Posted May 31, 2014 that particular line in the current download of the script is - if( $_POST['email'] && ereg( $matchstring, $_POST['email'] ) ) if this is what the op started with, you somehow removed the ['email'] parts when you changed from ereg() to preg_match() Quote Link to comment https://forums.phpfreaks.com/topic/288882-enthusiast-join-form-error/#findComment-1481466 Share on other sites More sharing options...
Ashes Posted May 31, 2014 Author Share Posted May 31, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/288882-enthusiast-join-form-error/#findComment-1481468 Share on other sites More sharing options...
gizmola Posted May 31, 2014 Share Posted May 31, 2014 **sigh** Change that line to: if( $_POST['email'] && preg_match( $matchstring, $_POST['email'] ) ) Quote Link to comment https://forums.phpfreaks.com/topic/288882-enthusiast-join-form-error/#findComment-1481486 Share on other sites More sharing options...
Ashes Posted May 31, 2014 Author Share Posted May 31, 2014 (edited) Hey, I told you in the first post that I know almost nothing about PHP. I wasn't joking. 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 May 31, 2014 by Ashes Quote Link to comment https://forums.phpfreaks.com/topic/288882-enthusiast-join-form-error/#findComment-1481487 Share on other sites More sharing options...
mac_gyver Posted May 31, 2014 Share Posted May 31, 2014 the code setting $matchstring will also need to be changed (needs delimiters around the search pattern.) please post the line(s) immediately prior to line 141 that is/are defining $matchstring. Quote Link to comment https://forums.phpfreaks.com/topic/288882-enthusiast-join-form-error/#findComment-1481490 Share on other sites More sharing options...
Ashes Posted May 31, 2014 Author Share Posted May 31, 2014 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.'; Quote Link to comment https://forums.phpfreaks.com/topic/288882-enthusiast-join-form-error/#findComment-1481494 Share on other sites More sharing options...
Ashes Posted June 7, 2014 Author Share Posted June 7, 2014 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!! Quote Link to comment https://forums.phpfreaks.com/topic/288882-enthusiast-join-form-error/#findComment-1482155 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.