Help figure out why in this form, when you click on a picture with a captcha (to download a new picture), it gives:

Fatal error: Maximum execution time of 30 seconds exceeded in /home/spravkab/public_html/useradd.php on line 66? And it gives out when the form is completed, and when it is clean, everything works fine.

<? session_start(); //echo $_SESSION['captcha_keystring']; include("config.php"); $dbh = mysql_connect($host, $user, $pswd) or die("Не могу соединиться с MySQL."); mysql_select_db($database) or die("Не могу подключиться к базе."); mysql_query("SET NAMES cp1251"); $name = $_POST["nameshort"]; $fullname = $_POST["namefull"]; $orgform = $_POST["type"]; $phones = mysql_real_escape_string($_POST["phone"]); $faxes = mysql_real_escape_string($_POST["fax"]); $add_phones = mysql_real_escape_string($_POST["morephones"]); $address = $_POST["address"]; $category = mysql_real_escape_string($_POST["category"]); $efforts = mysql_real_escape_string($_POST["Comments"]); $email = mysql_real_escape_string($_POST["email"]); $website = mysql_real_escape_string($_POST["site"]); $skype = mysql_real_escape_string($_POST["skype"]); $icq = mysql_real_escape_string($_POST["icq"]); $lon = mysql_real_escape_string($_POST["lon"]); $lat = mysql_real_escape_string($_POST["lat"]); $mapp = $_POST["mapp"]; $refresh = $_POST["refresh"]; $URL="index.php"; $accept = 1; if ($refresh == '1') { $URL = "userreg.php?r=1&nameshort=$name&namefull=$fullname&type=$orgform&phone=$phones&fax=$faxes&morephones=$add_phones&address=$address&category=$category&Comments=$efforts&email=$email&site=$website&skype=$skype&icq=$icq&lon=$lon&lat=$lat&mapp=$mapp"; $accept = 0; } elseif (($name == '') or ($fullname == '') or ($orgform = '') or ($phones == '') or ($address == '')) { $URL = "userreg.php?nameshort=$name&namefull=$fullname&type=$orgform&phone=$phones&fax=$faxes&morephones=$add_phones&address=$address&category=$category&Comments=$efforts&email=$email&site=$website&skype=$skype&icq=$icq&lon=$lon&lat=$lat&mapp=$mapp"; $accept = 0; } elseif(isset($_SESSION['captcha_keystring']) && $_SESSION['captcha_keystring'] !== $_POST['captcha']){ $URL = "userreg.php?e=1&nameshort=$name&namefull=$fullname&type=$orgform&phone=$phones&fax=$faxes&morephones=$add_phones&address=$address&category=$category&Comments=$efforts&email=$email&site=$website&skype=$skype&icq=$icq&lon=$lon&lat=$lat&mapp=$mapp"; $accept = 0; } elseif(preg_match('/http:\/\//', $address)) { // spam protection $accept = 0; } elseif(preg_match('/http:\/\//', $efforts)) { // spam protection $accept = 0; } unset($_SESSION['captcha_keystring']); $sort_name = preg_replace("/^[«\'\"“]/", "", $name); if ($mapp != 'on') { $lon=''; $lat=''; } $pattern = '/"([^a-zA-Z].*)"/'; $replacement = '«$1»'; while (preg_match($pattern, $name)) { $name = preg_replace($pattern, $replacement, $name); } while (preg_match($pattern, $fullname)) { $fullname = preg_replace($pattern, $replacement, $fullname); } while (preg_match($pattern, $address)) { $name = preg_replace($pattern, $replacement, $address); } $pattern = '/»»/'; $replacement = '»'; while (preg_match($pattern, $name)) { $name = preg_replace($pattern, $replacement, $name); } while (preg_match($pattern, $fullname)) { $fullname = preg_replace($pattern, $replacement, $fullname); } $website = preg_replace("/^http:\/\//", "", $website); $website = preg_replace("/\/$/", "", $website); $query = "INSERT INTO `wp_organisations` (`o_name`, `o_fullname`, `o_orgform`, `o_phones`, ". "`o_faxes`, `o_add_phones`, `o_address`, `o_category`, `o_email`, `o_website`, `o_skype`, ". "`o_icq`, `o_efforts`, `lon`, `lat`, `pending`, `created`, `sort_name`) VALUES ". "('$name', '$fullname', '$orgform', '$phones', '$faxes', '$add_phones', '$address', ". "'$category', '$email', '$website', '$skype', '$icq', '$efforts', '$lon', '$lat', '1', NOW(), '$sort_name')"; //echo ($query); if ($accept) { $res = mysql_query($query); } mysql_close($dbh); header ("Location: $URL"); ?> 

    2 answers 2

    This error in this code can only be in the inside of a while . You can use exit(); to determine in which loop the error occurs exit(); .
    In this code snippet, after each loop, put the exit() function. for example

     while (preg_match($pattern, $name)) { $name = preg_replace($pattern, $replacement, $name); }exit('Ок'); while (preg_match($pattern, $fullname)) { $fullname = preg_replace($pattern, $replacement, $fullname); } while (preg_match($pattern, $address)) { $name = preg_replace($pattern, $replacement, $address); } $pattern = '/»»/'; $replacement = '»'; while (preg_match($pattern, $name)) { $name = preg_replace($pattern, $replacement, $name); } while (preg_match($pattern, $fullname)) { $fullname = preg_replace($pattern, $replacement, $fullname); } 

    If the message is OK, but it did not load for a long time, then transfer the function to the end of the next cycle. If the message does not give, you can understand where the error. Good luck!

      Well, since the source code of the server part of your script is inaccessible to mere mortals, it is unlikely anyone will be able to tell why. Apparently, one or several field values ​​are validated in useradd.php , and if they are not empty, then they are processed. Something like this. Well, there, most likely, something like a cycle occurs with this data (erroneous or infinite, I won’t guess, the script itself is not visible). Therefore, the Maximum execution time error is thrown in 30 seconds, since this is a preventive measure in the settings of PHP itself. Roughly speaking, there are two things to consider: either an infinite loop ( loop ) or a timeout from some third-party built-in function that checks the data (and, apparently, it sends data when the fields are not empty).

      Addition:

       $pattern = '/"([^a-zA-Z].*)"/'; $replacement = '«$1»'; while (preg_match($pattern, $name)) { $name = preg_replace($pattern, $replacement, $name); } while (preg_match($pattern, $fullname)) { $fullname = preg_replace($pattern, $replacement, $fullname); } while (preg_match($pattern, $address)) { $name = preg_replace($pattern, $replacement, $address); } 

      Line 66, I suppose this is the last?

       $name = preg_replace($pattern, $replacement, $address); 

      And the question is: should there be exactly $name= ? Or $address ?

      • Completed the question. - Aviko
      • In my opinion, it was easier to say, "Dude, you have a joint in some kind of cycle." - zenith
      • Replaced with an address, now everything is overloading normally, only why does the form come empty? .. - Aviko
      • Well, I would advise you now to set echo / print for each "doubtful" variable "from line to line", or to start debug to see what value is assigned to each variable as the script passes. It's hard for me to do this, because the rest of the engine is on your server, not on mine. - void
      • I noticed such a feature - it hangs only on the address and only where there are quotes (case "b", for example), can the key be here? - Aviko