Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Request page too large", Best way to refactor?
    text
    copied!<p>The following code should check if either a # or @ symbol has been found in a string. The regex should find each and every @ or # (kind of like Twitter does)and should either place each instance it found into the <code>messages</code> table (if it was an @ symbol), or if it was a # symbol it should insert the instance into the <code>hashtags</code> table or update an existing record if the hashtag is already in the table.<br> Currently, the script itself works fine, but when using the code with javascript through AJAX, the console responds by saying the requested entity (this script) is too large (or something of that caliber). I'd assume its getting stuck in an endless loop, but so far I haven't found a (working) better way to do this. So, what would be a better way of coding this?</p> <pre><code>if (preg_match_all("/[@]+[A-Za-z0-9-_]+/i", $post, $matches)) { for ($i = 0;$i &lt;= $matches;$i++) { $match = str_replace("@", "", $matches[$i]); foreach($match as $key=&gt;$mVal) { $uMSQL = "INSERT INTO `messages` (`to`, `from`, `message`, `sent`) VALUES (:to, :from, '&lt;p&gt;tagged you in a post&lt;/p&gt;', NOW())"; $uMQ = $con-&gt;prepare($uMSQL); $uMQ-&gt;bindParam(':from', $author, PDO::PARAM_STR); $uMQ-&gt;bindParam(':to', $mVal, PDO::PARAM_STR); $uMQ-&gt;execute(); } } } if (preg_match_all("/[#]+[A-Za-z0-9-_]+/i", $post, $hashtags)) { for ($h = 0; $h &lt;= $hashtags; $h++) { $htMatched = $hashtags[$h]; foreach($htMatched as $key=&gt;$htVal) { $htCheck = "SELECT COUNT(hashtag) FROM `hashtags` WHERE `hashtag` = '$htVal'"; $htQ = $con-&gt;query($htCheck); $htExistence = $htQ-&gt;fetchColumn(); if ($htExistence &gt;= 1) { $addTU = "UPDATE `hashtags` SET `used` = used+1 WHERE `hashtag` = '$htVal'"; $updateHT = $con-&gt;exec($addTU); } else { $htMSQL = "INSERT INTO `hashtags` (`hashtag`) VALUES (:hashtag)"; $htMQ = $con-&gt;prepare($htMSQL); $htMQ-&gt;bindParam(':hashtag', $htVal, PDO::PARAM_STR); $htMQ-&gt;execute(); } } } } </code></pre> <p>AJAX</p> <pre><code> function sendData() { var hr = new XMLHttpRequest(); var url = "http://localhost/NextIt/ajax/sendPost.php"; var txtField = window.frames['richTextField'].document.body.innerHTML; var access = document.getElementById('postTo').selectedIndex; var acc = document.getElementById('postTo').options; var accss = acc[access].text; var vars = "post="+txtField+"&amp;access="+accss; hr.open("POST", url, true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if (hr.readyState === 4 &amp;&amp; hr.status === 200) { var return_data = hr.responseText; $('status').innerHTML = return_data; window.frames['richTextField'].document.body.innerHTML = ''; } } hr.send(vars); $('status').innerHTML = "Posting..."; } </code></pre> <p>The post_max_size is 8M.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload