Jump to content

Mko

Members
  • Posts

    56
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Mko's Achievements

Member

Member (2/5)

0

Reputation

  1. Are you trying to use a form to process this 'table'? If so, check out this link for some help. As to the if statement you posted at the bottom of your post, I'm confused as to what you're trying to do with it. Are you trying to do a comparison or an AND/OR statement?
  2. It's an identical issue to the one you fixed previously. Change: ( "DOMAIN", $config['do".__FILE__] ); to ( "DOMAIN", $config["do".__FILE__] ); From what I can tell, there are quite a handful of silly mistakes in this script. I'd suggest probably finding (or writing) a better version, as who knows how many other bugs and possible exploits/vulnerabilities there could be in this code if the author couldn't even correct a simple issue.
  3. Thanks! It turned out I forgot to add this line in after declaring $conn1: $conn1->select_db("database");
  4. Hello all, I'm currently getting strange errors when trying to execute my code. First off, here is what I have so far: class DB extends MySQLi { public function __construct() { $conn = @$this->connect(HOST, USERNAME, PASSWORD); if ($this->connect_errno) { die("<br />Could not connect to MySQLi Database: " . $this->connect_error); } return $conn; } } ...and my code: $conn1 = new DB(); $stmt = $conn1->stmt_init(); $stmt->prepare("UPDATE `user` SET `f1` = 2, `f2` = (?), `f3` = (?) WHERE `w1` = (?)"); $stmt->bind_param('ssi', $p1, $p2, $p3); $stmt->execute(); $stmt->close(); The errors I get: Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: invalid object or resource mysqli_stmt in /home/208/public_html/a1/p.php on line 61 Warning: mysqli_stmt::execute() [mysqli-stmt.execute]: invalid object or resource mysqli_stmt in /home/208/public_html/a1/p.php on line 62 Warning: mysqli_stmt::close() [mysqli-stmt.close]: invalid object or resource mysqli_stmt in /home/208/public_html/a1/p.php on line 63 I'm really confused as to what the issue is. I do know mysqli_stmt is its own class, but I'm not sure if declaring my DB class as mysqli_stmt would fix it, either. Does anyone know what I'm doing wrong? Thanks for any and all help, Mark
  5. Hey all, I've recently encountered a pesky bug I've been unable to really fix. First off, here's a picture showing roughly how my site is (FTP, blanked out directories that are irrelevant to my issue): Now, I have another directory in the /essentials/ folder, called /includes/, where I have 2 files, called header.php and footer.php. Within header.php, I have this code: <?php chdir("community/"); require_once('./global.php'); ?> Now, I have a file in the /account/ folder called index.php. It contains this code: include_once($_SERVER['DOCUMENT_ROOT'].'/essentials/includes/header.php'); include_once($_SERVER['DOCUMENT_ROOT'].'/essentials/includes/footer.php'); I've tried using chdir in this file, yet it doesn't work! Anyways, this should function correctly. Yet, I encounter an odd issue when I execute this code. Error: Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /home/208/public_html/essentials/includes/header.php on line 5 Warning: require_once(./global.php) [function.require-once]: failed to open stream: No such file or directory in /home/208/public_html/essentials/includes/header.php on line 6 Fatal error: require_once() [function.require]: Failed opening required './global.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/208/public_html/essentials/includes/header.php on line 6 So, for some reason, I'm having issues. If my code in /account/index.php includes header/footer correctly, I get errors in my header.php file. If it doesn't include the header/footer files, then I get another issue, which says: Warning: include_once(/home/208/public_html/account/essentials/includes/header.php) [function.include-once]: failed to open stream: No such file or directory in /home/208/public_html/account/index.php on line 3 Warning: include_once() [function.include]: Failed opening '/home/208/public_html/account/essentials/includes/header.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/208/public_html/account/index.php on line 3 Warning: include_once(/home/208/public_html/account/essentials/includes/footer.php) [function.include-once]: failed to open stream: No such file or directory in /home/208/public_html/account/index.php on line 4 Warning: include_once() [function.include]function.include]: Failed opening '/home/208/public_html/account/essentials/includes/footer.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/208/public_html/account/index.php on line 4 So, my question is: What would be the correct way to fix this issue? Would I need to change the contents of the header.php file, the index.php file, or both? Thanks for all help, Mark
  6. Is your issue that mysql_fetch_field() is depreciated so you're getting a warning or do you have another error?
  7. You can always opt for using MySQL, but it has become depreciated.
  8. You'd need to change up some features of your code. For connecting, use $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); And for querying, use $mysqli->query($query); Most of the MySQL features are the same in MySQLi, but they just include the i in the function name. Be sure to go to php.net to read up on the functionality of all the MySQLi functions, as not all of them are completely alike.
  9. You could always just use mysqli_fetch_field(). Read more: http://php.net/manua...etch-fields.php
  10. I did some debugging with my previous version. From what I could tell, the Regular Expression I had (/^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/) wasn't functioning properly -- yielding the 30 second execution time warning. Your example worked! I can follow everything you posted, except for one hiccup, regarding the Regular Expression. My question is: can you explain to me what the functionality of the # and #i before and after the Regular Expression ('#(</?([a-z]+)[^>]*>)#i') is? Thanks a bunch for your continued help , Mark
  11. The was just an issue with View Source for some reason :s Anyways, I implemented your code, but for some reason, I get this error when I run my script: Fatal error: Maximum execution time of 30 seconds exceeded in /home/mko/public_html/home.php on line 189 My current code: <?php $conn = new DB(); $query = $conn->query("query here;"); if (mysqli_num_rows($query) > 0) { while ($result = mysqli_fetch_array($query)) { $body = $result['pagetext']; $parser = new vB_BbCodeParser($vbulletin, fetch_tag_list(), true); $parsed_text = $parser->do_parse($body); $parts = preg_split("/^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/", $parsed_text, -1, PREG_SPLIT_DELIM_CAPTURE); $cut = true; // first in $parts is regular text $length = 0; // so far $opentags = array(); // stack of tags needing to close $output = ""; // shortened version foreach ($parts as $p) { if ($cut) { // if you need to trim then go ahead, then break out of the loop // otherwise add to $length if ($length > 250) { break; } else { $length .= $p; } } else { // look at the captured html tag // if it opens and doesn't self-close then // - add the tag name to $opentags // if it closes then // - optionally check that it agrees with the top of the $opentags stack // - pop off $opentags if ($p.substr($p, 1, 1) != "/") { $opentags .= $p; } else if ($p.substr($p, 1, 1) == "/") { unset($opentags[$p]); } } $output .= $p; $cut = !$cut; } // now close off the remaining open tags foreach ($opentags as $tag) { $output .= "</{$tag}>"; } echo '<div id="a1">'; echo '<div class="b">'; echo $output.'...'; echo '<div class="c"></div>'; echo '<div class="d">[<a href="">Read More...</a>]'; echo '</div>'; echo '<div class="e"></div></div></div>'; } } else { echo 'No news!'; } ?> Am I implementing this correctly? Thanks, Mark
  12. Hello all, I'm recently writing a script on the homepage that would display certain threads from certain forum categories. My current SQL query and fetching the contents work well, except I encounter an odd issue when using the substring method on the fetched contents to limit the characters displayed. Just so you're aware, I'm parsing the contents of the thread's post through vBulletin's BBCodeParser, yet that's not the issue. Here's a bit of background regarding my code/issue. Current Code (only included the important stuff): $parsed_text = $parser->do_parse($body); $message_pre = substr($parsed_text, 0, 500); $message = substr($message_pre, 0, strrpos($message_pre, ' ')); echo '<div id="a1"> echo '<div class="b">'; echo $message.'...'; echo '<div class="c"></div>'; echo '<div class="d">[<a href="">Read More...</a>]'; echo '</div>'; echo '<div class="e"></div></div></div>'; So, that's all fine. However, let's get some example database contents: [b]bold[/b] [i]italic[/i] [u]underline[/u] [center] center [/center] [left]left [/left] [right]right [/right] [url="http://google.com"]google.com[/url] [url="http://google.com"]url1[/url] [url="http://google.com"]url2[/url] [email="1@2.com"]1@2.com[/email] [email=1@2.com]1@2.com2[/email] [img=http://google.com] [size=4]yo[/size] [size="4"]yo2[/size] [font="Book Antiqua"]test[/font] [font=Book Antiqua]test2[/font] [color="Red"]hey[/color] [color="#0048C0"]hey2[/color] [list] [*]hello [*]world [/list] [list=1] [*]list2 [*]list2_1 [/list] Now, the BBCodeParser successfully parses the BBCode like it should and spits back some HTML, which I store inside the $parsed_text variable. However, I have an odd issue with the $message variable. Some of the HTML that is parsed seems to not terminate correctly, thus messing up my style. Here's an example of the issue in action (HTML output): <b>bold</b><br /> <i>italic</i><br /> <u>underline</u><br /> <div align="[url=""]center[/url]"> center<br /> </div><div align="[url=""]left[/url]">left<br /> </div><div align="[url=""]right[/url]">right<br /> </div><a href="[url="view-source:http://google.com/"]http://google.com[/url]" target="[url=""]_blank[/url]">google.com</a><br /> <a href="[url="view-source:http://google.com/"]http://google.com[/url]" target="[url=""]_blank[/url]">url1</a><br /> <a href="[url="view-source:http://google.com/"]http://google.com[/url]" target="[url=""]_blank[/url]">url2</a><br /> <a href="[email="mark@mko.com"]mailto:1@2.com[/email]">1@2.com</a><br /> <a href="[email="mark@mko.com"]mailto:1@2.com[/email]">1@2.com2</a><br /> <img...<div class="[url=""]clear[/url]"></div><div class="[url=""]news_bottom[/url]">[<a href="">Read More...</a>]</div> As you can most likely see, the contents of $message end with <img, because of the space before the src in <img src. My question is: What would be the correct way to go about limiting the amount of characters displayed AND preventing unclosed HTML tags from being displayed on the last line of the $message variable's content? Thanks for any and all help, Mark
  13. Alright. I've used what you've said and implemented it successfully (I think). How does this look? My file (called test.php, this is NOT the class): include_once('functions.php'); define("HOST", "localhost"); define("USERNAME", "a"); define("PASSWORD", "b"); $conn_o = new DB(HOST, USERNAME, PASSWORD); $query = $conn_o->udb_query($conn_o, "SELECT * FROM `user` WHERE `userid`='" . (int) $vbulletin->userinfo['userid'] . "';"); $conn_o->close(); $row = mysqli_fetch_array($query); The class (called functions.php): class DB extends MySQLi { public function udb_query($mysqli, $query){ if (!$this->select_db(USER_DATABASE)){ die('Could not change database!'); } $res = $this->query($query); if (!$res){ die("Error running Query ('" . $pquery . "'): " . mysqli_error($mysqli)); } return $res; } public function promo_query($mysqli, $query){ if (!$this->select_db(PROMO_DATABASE)){ die('Could not change database!'); } $res = $this->query($query); if (!$res){ die("Error running Query ('" . $pquery . "'): " . mysqli_error($mysqli)); } return $res; } } How does it look? Also, would it be better if I made a function inside the class to connect so I'd remove the need to have to define the DB values in the file? Thanks for your continued help
  14. Thanks for the reply! One final question: When you say "store the connection variable as a class level variable", I'm a bit confused as to what you mean by that. Could you provide an example of declaring a class level variable, please? Thanks
  15. Hey all, I've written some relatively straightforward functions designed to simply query a database. However, some of my friends have told me that what I currently have written is 'inefficient'. I'm a bit confused as to what they truly meant and what aspects of my code are inefficient :-\ My code: function udb_sqli_query($pquery) { $mysqli = new mysqli(HOST, USERNAME, PASSWORD, USER_DATABASE); if (!@$mysqli) { die("Could not connect to MySQLi Database: " . mysqli_error($mysqli)); } $query = @mysqli_query($mysqli, $pquery); if (!@$query) { die("Error running Query ('" . $pquery . "'): " . mysqli_error($mysqli)); } $mysqli->close(); return $query; } function promo_sqli_query($pquery) { $mysqli = new mysqli(HOST, USERNAME, PASSWORD, PROMO_DATABASE); if (!@$mysqli) { die("Could not connect to MySQLi Database: " . mysqli_error($mysqli)); } $query = @mysqli_query($mysqli, $pquery); if (!@$query) { die("Error running Query ('" . $pquery . "'): " . mysqli_error($mysqli)); } $mysqli->close(); return $query; } Essentially, I'm wondering about: a. What parts in my code could be made more efficient? b. If connecting to the database every time a query is executed is the wrong way to go about doing this? c. If I shouldn't be connecting to the database every time a query is executed, what would be a better way so my code is more efficient while yielding the same results? Thanks for any and all help, Mark
×
×
  • 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.