Ricky55 Posted August 4, 2018 Share Posted August 4, 2018 Hi guys PHP beginner. I have just moved my site to a new server, the old server had an older version of PHP, 5. something and the new server has version 7. I have a script that powers this page https://www.jaybe.com/guarantee-register/ It just sends an email back to the user and also posts the form contents to a mysql database. A developer that I used to work with set this up for me a long time back. Now when I run the script I get this errorFatal error: Uncaught Error: Call to undefined function ereg() in /var/www/jaybe.com/public_html/_/scripts/guarantee.php:37 Stack trace: #0 {main} thrown in /var/www/jaybe.com/public_html/_/scripts/guarantee.php on line 37 The code from the script is here:- <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $after = "/guarantee-register/thanks.php"; $oops = "/guarantee-register/error.php"; if (isset($_POST['submit']) || isset($_POST['submit_x']) || $_SERVER['REQUEST_METHOD'] == "POST") { $exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javascript|alert)/i"; $profanity = "/(test)/i"; $spamwords = "/(viagra|phentermine|tramadol|adipex|advai|alprazolam|ambien|ambian|amoxicillin|antivert|blackjack|backgammon|texas|holdem|poker|carisoprodol|ciara|ciprofloxacin|debt|dating|porn)/i"; $bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer)/i"; if (preg_match($bots, $_SERVER['HTTP_USER_AGENT'])) { exit("<p>Known spam bots are not allowed.</p>"); } foreach ($_POST as $key => $value) { $value = trim($value); if (empty($value)) { if ($key != "email") { exit("<p>Please go back and complete the required fields.</p>"); } } elseif (preg_match($exploits, $value)) { exit("<p>Exploits/malicious scripting attributes aren't allowed.</p>"); } elseif (preg_match($profanity, $value) || preg_match($spamwords, $value)) { exit("<p>Please keep things clean, no naughty words!</p>"); } $_POST[$key] = stripslashes(strip_tags($value)); } if (!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,6})$",strtolower($_POST['email']))) { exit("<p>How can we reply if you don't provide us with a valid email address?</p>"); } conn(); $sql = "INSERT INTO guarantee_reg (`gender`, `forename`, `surname`, `address`, `postcode`, `email`, `product`, `date_purchased`, `retailer`, `opt_in`) VALUES ( '" . mysql_real_escape_string($_POST['gender']) . "', '" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['surname']) . "', '" . mysql_real_escape_string($_POST['address']) . "', '" . mysql_real_escape_string($_POST['postcode']) . "', '" . mysql_real_escape_string($_POST['email']) . "', '" . mysql_real_escape_string($_POST['product']) . "', '" . mysql_real_escape_string($_POST['date']) . "', '" . mysql_real_escape_string($_POST['retailer']) . "', '" . mysql_real_escape_string($_POST['opt-in']) . "')"; qry($sql); $recipient = "{$_POST['email']}"; $subject = "Your Jay-Be Guarantee Confirmation"; $message .= "Dear {$_POST['name']}, \n\n Thank you for completing the Jay-Be guarantee registration form. This email is your guarantee registration confirmation, you may wish to print it out for future reference.\n\n"; $year = date('y'); $month = date('m'); $message = ""; $message .= 'Reference number: JB' . $year . $month . "\n\n"; $message .= "The details you provided are as follows: \n\n"; $message .= "Title: {$_POST['title']} \n\n"; $message .= "First Name: {$_POST['name']} \n\n"; $message .= "Surname: {$_POST['surname']} \n\n"; $message .= "Address:\n{$_POST['address']} \n\n"; $message .= "Postcode: {$_POST['postcode']} \n\n"; $message .= "Email: {$_POST['email']} \n\n"; $message .= "Product purchased: {$_POST['product']} \n\n"; $message .= "Date purchased: {$_POST['date']} \n\n"; $message .= "Retailer purchased from: {$_POST['retailer']} \n\n"; $message .= "Added to our marketing database (no if not specified): {$_POST['opt-in']} \n\n"; $headers .= "From: {$_POST['email']}"; if (mail($recipient,$subject,$message,$headers)) { echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$after\">"; } else { echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$oops\">"; } } function conn() { $host='localhost'; if($_SERVER['SERVER_ADDR']!='127.0.0.1') { $user='user'; $pwd='xxx'; $db='fff'; } else { $user='root!'; $pass=''; $db='fff'; } $conn = mysql_connect($host, $user, $pwd) or die ("<h1>mysql_connect Error</h1>\n <ul>\n <li>Error in: " . $_SERVER['PHP_SELF'] . "</li>\n <li>Selecting database : $db</li>\n <li>With username: $user</li>\n <li>And Password: $pass</li>\n <li>mysql_error: " . mysql_error() . "</li>\n </ul>\n"); mysql_select_db($db, $conn) or die("<h1>mysql_select_db Error</h1>\n <ul>\n <li>Error in: " . $_SERVER['PHP_SELF'] . "</li>\n <li>Selecting database : $db</li>\n <li>With username: $user</li>\n <li>And Password: $pass</li>\n <li>mysql_error: " . mysql_error() . "</li>\n </ul>\n"); return $conn; } function qry($sql) { $res = mysql_query($sql) or die("<h1>Error Querying Database</h1>\n<ul><li>SQL: $sql</li>\n<li>Error: " . mysql_error() . "</li>\n</ul>"); return $res; } function qry_row($sql) { $res = qry($sql); $row = mysql_fetch_assoc($res); return $row; } ?> If anyone can shed any light I'd be very grateful. Thanks Richard Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 4, 2018 Share Posted August 4, 2018 Once again the failure to RTFM is the cause of one's problem. Look up ereg in the official PHP manual. Sure I could be extremely helpful and give you the link (not!) except I believe you need to practice using the manual. Quote Link to comment Share on other sites More sharing options...
benanamen Posted August 5, 2018 Share Posted August 5, 2018 You have many more problems than that. The whole script is written with obsolete MySQL code that has been removed from PHP. This script will not work at all. The entire script needs to be re-written. Quote Link to comment 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.