Jump to content

CK9

Members
  • Posts

    28
  • Joined

  • Last visited

    Never

Everything posted by CK9

  1. and I'm a dumbass >.< lol, thanks for pointing that out, been so long since I've done anything with php that I didn't even notice that, and you indirectly made me realize something else I missed (removed a function that I actually need to use for the contents to go in the correct location).
  2. Hello, I've been playing around with a coding experiment that I did previously. I've been teaching myself javascript and css to take some of the load off the server side of things, but in changing my code, I've come to a new error: The first thing I did was search for the error. I don't have the function declared more than once, and include_once() did not fix the issue. Here is what I have: list.php which has not changed and worked fine prior to making the changes: <?php include("db.class.php"); include("db.config.php"); $db = new databaseConnection($config['user'],$config['pass'],$config['database']); $g = $_GET['g']; $s = $_GET['s']; $t = $_GET['t']; function tablestart($a = '1') { echo "<table border='" . $a . "' cellpadding='10' cellspacing='0' align='center' width='80%' style='color: #C0C0C0'>\n"; } function contents($db, $table, $a, $b = '1', $c = '1') { $db->query("SELECT * FROM $table"); while($row = $db->fetch_array()) { if($row['level'] <= $_SESSION['ulevel']) { echo "<tr><td width='5%'><!--indicator--></td><td width='80%'><a href='index.php?pg=h&g='" . $row['g']; if(($a > '1') && ($row['g'] == $b)) { echo "&s=" . $row['s']; if(($a > '2') && ($row['s'] == $c)) { echo "&t=" . $row['t']; } } } echo "' style='color: #C0C0C0 ; text-decoration: none'><font size='4'>" . $row['name'] . "</font><br /><fpnt size='3'>" . $row['desc'] . "</td><td width='15%'><!--last update--></td></tr>\n"; } } if(empty($_SESSION['ulevel'])) { $_SESSION['ulevel'] = '0'; echo "<font color='#CC0000'><center>You need to register to post in these forums.</center></font><br />\n"; } if(empty($g)) { tablestart(); contents($db, 'fgroup', '1'); echo "</table>\n"; } elseif(empty($s)) { tablestart(); contents($db, 'section', '2', $g); echo "</table>\n"; } elseif(empty($t)) { tablestart('0'); echo "<tr><td width='80%'></td><td><!--new topic--></td></tr>\n</table>\n"; tablestart(); contents($db, 'topic', '3', $g, $s); echo "</table>\n"; } elseif(!empty($t)) { tablestart('0'); echo "<tr><td width='80%'></td><td><!--new topic and reply--></td></tr>\n</table>\n"; $data = file_get_contents('post.txt'); $post = explode("<!--p-->", $data); $length = count($post); tablestart('1'); for($z = '0'; $z < $length; $z ++) { $i = '0'; $cont = explode("<!--e-->", $post[$pos]); echo "<tr><td><b>" . $cont[$i] . "</b><br /><!--future additions--></td><td>\n<table width='100%' style='font-size: xx-small'>\n<tr><td height='3' width='75%'>"; $i ++; echo "Posted on" . $cont[$i] . "</td><td height='3' width='25%'><!--future additions--></td></tr><tr><td width='100%'>"; $i ++; echo $cont[$i] . "</td></tr></table></td></tr>\n"; } echo "</table>\n"; } ?> index.php with the original code set within an extended comment: <?php session_start(); if(empty($_GET['pg'])) { $pg = 'h'; } else { $pg = $_GET['pg']; } switch($pg) { case 'h': $a = 'home'; $b = 'tlsection-h'; include_once('list.php'); break; case 'p': $a = 'posting'; $b = 'tlsection-p'; include('post.php'); break; case 'l': $a = 'logging'; $b = 'tlsection-l'; include('log.php'); break; case 'v': $a = 'verification'; $b = 'tlsection-v'; include('verify.php'); break; case 'm': $a = 'members'; $b = 'tlsection-m'; include('mem.php'); break; } ?> <html> <head> <!-- meta tags to go here --> <?php echo " <title>Omega Command - Forum - " . $a . "</title>\n"; ?> <!-- Special thanks to TH300 for letting me look through his css coding to learn from it --> <link rel='stylesheet' type='text/css' href='style.css' /> </head> <body> <div class='PageBody'> <?php echo " <div class='" . $b . "'>\n"; ?> <div class='HeaderSection'> <div class='HeaderBanner'> <img src='elements/headbar2.png' alt='Yup, it's a forum'> </div> <div class='NavBar'> <?php require_once('navigation.php'); ?> </div> </div> <!-- end header --> <div class='MainSection'> <div class='NavMenu'> <!-- need to figgure out what goes here --> </div> <!-- end nav menu --> <div class='contents'> <?php pageswitch($pg); ?> </div> <!-- end contents --> </div> <!-- end main section --> <div class='FooterSection'> <!-- optional footer image --> </div> <!-- end footer section --> </div> </div> </body> </html> /*<?php session_start(); ?> <body bgcolor='#000000'> <?php function pageswitch($pg) { include("header.php"); switch ($pg) { case 'h': include('list.php'); break; case 'p': include('post.php'); break; case 'l': include('log.php'); break; case 'v': include('verify.php'); break; case 'm': include('mem.php'); break; } include('footer.html'); } ?> <table width='100%' border='0' cellpadding='0' cellspacing='0' align='center'> <tr><td width='100%'><center><img src='elements/headbar.png'></center></td></tr> <tr><td width='100%' height='2' bgcolor='#C0C0C0'></td></tr><tr><td height ='10' width='100%'> <?php require('navigation.php'); ?> </td></tr> <tr><td width='100%' height='2' bgcolor='#C0C0C0'></td></tr> </table> <table width='100%' border='0' cellpadding='0' cellspacing='0' align='center'><tr> <?php if(empty($_GET['pg'])) { $page = 'h'; } else { $page = $_GET['pg']; } if($page == 'h' && !isset($_GET['g'])) { echo "<td width='24%'>"; include('sidebar.php'); echo "</td><td width='1' height='100%' bgcolor='#C0C0C0'></td><td width='75%'>"; } else { echo "<td width='100%'>"; } echo "<br />"; pageswitch($page); ?> <br /></td></tr></table> <table width='100%' border='0' cellpadding='0' cellspacing='0' align='center'> <tr><td width='100%' height='2' bgcolor='#C0C0C0'></td></tr> </table><br /> <center><font color='#C0C0C0' size='2'>This forum was coded by CK9 as an experiment with PHP. It is very basic and does not garuntee security. Refrain from storing sensitive information here.</center>*/ As you can see, on list.php line 10 is the function declaration and line 13 is the closing brace. From what I see, and the fact this page was working perfectly before the change, this error should not be happening... Is there something obvious I'm just not seeing?
  3. Maybe there is a server setting that has an unforseen effect. Unfortunately, now that that part is fixed, I'm having issues with my login system that I didn't have without using a class for database connection. I'm sure it's just a simple thing though, probably didn't properly set up the username and password comparison (again, heh).
  4. So, if I change it to, say, fgroup it should clear up? Apparently so =) Thanks for all the help and sorry for any frustrations, heh.
  5. I had added the "$db->..." into the second function rather than adding $db as an argument.... After reviewing the code again, I realized the first itteration of the global variable (inside the tablestart function) was a placement error that I only partially corrected, so that gets removed entirely... Here's what I have now: <?php include("db.class.php"); include("db.config.php"); $db = new databaseConnection($config['user'],$config['pass'],$config['database']); $g = $_GET['g']; $s = $_GET['s']; $t = $_GET['t']; function tablestart($a = '1') { echo "<table border='" . $a . "' cellpadding='10' cellspacing='0' align='center' width='80%' style='color: #C0C0C0'>\n"; } function contents($db, $table, $a, $b = '1', $c = '1') { // global $db; $db->query("SELECT * FROM $table"); while($row = $db->fetch_array()) { if($row['level'] <= $_SESSION['ulevel']) { echo "<tr><td width='5%'><!--indicator--></td><td width='80%'><a href='index.php?pg=h&g='" . $row['g']; if(($a > '1') && ($row['g'] == $b)) { echo "&s=" . $row['s']; if(($a > '2') && ($row['s'] == $c)) { echo "&t=" . $row['t']; } } } echo "' style='color: #C0C0C0 ; text-decoration: none'><font size='4'>" . $row['name'] . "</font><br /><fpnt size='3'>" . $row['desc'] . "</td><td width='15%'><!--last update--></td></tr>\n"; } } if(empty($_SESSION['ulevel'])) { $_SESSION['ulevel'] = '0'; echo "<font color='#CC0000'><center>You need to register to post in these forums.</center></font><br />\n"; } if(empty($g)) { tablestart(); contents($db, 'group', '1'); echo "</table>\n"; } elseif(empty($s)) { tablestart(); contents($db, 'section', '2', $g); echo "</table>\n"; } elseif(empty($t)) { tablestart('0'); echo "<tr><td width='80%'></td><td><!--new topic--></td></tr>\n</table>\n"; tablestart(); contents($db, 'topic', '3', $g, $s); echo "</table>\n"; } elseif(!empty($t)) { tablestart('0'); echo "<tr><td width='80%'></td><td><!--new topic and reply--></td></tr>\n</table>\n"; $data = file_get_contents('topics/g' . $g . 's' . $s . 't' . $t . '.txt'); $post = explode("<!--p-->", $data); $length = count($post); tablestart('1'); for($z = '0'; $z < $length; $z ++) { $i = '0'; $cont = explode("<!--e-->", $post[$pos]); echo "<tr><td><b>" . $cont[$i] . "</b><br /><!--future additions--></td><td>\n<table width='100%' style='font-size: xx-small'>\n<tr><td height='3' width='75%'>"; $i ++; echo "Posted on" . $cont[$i] . "</td><td height='3' width='25%'><!--future additions--></td></tr><tr><td width='100%'>"; $i ++; echo $cont[$i] . "</td></tr></table></td></tr>\n"; } echo "</table>\n"; } ?> which now brings up which points me to either the class file or the database itself...the class file doesn't have the word 'group' anywhere in it, so it has to be something with the database...looking at that I find a spelling error in the table name...correcting the error doesn't clear the error...I use phpmyadmin for everything related to the database itself, so I'm not sure what the error is pointing at.
  6. Currently, all the page codes are the same as posted in the first post (and whichever number the config code is in). I haven't done anything to permanantly modify the code. After running the test with the value dump lines, I removed them in order to keep the code the same as what is seen in this topic so that suggestions could be more quickly tested.
  7. Here's what I did while working on a project with a few other people: //this section is a bit unrelated, but I left it in so I can explain where the session_start() is at <? $sp = $_GET['pg']; function pgswtch($sp) { include("header.html"); echo "<table cols='2' border='0' cellpadding='10' cellspacing='0' align='center' width='100%'>"; echo "<tr>"; echo "<td width='16%'>"; include('navbar.html'); echo "</td><td>"; switch($sp) { case 'info': include('info.html'); break; case 'maps': include('maplist.html'); break; case 'images': include('piclist.html'); break; case 'other': include('misc.html'); break; } echo "</td></tr></table>"; include('footer.html'); } //and this is where it seems the most relevant to what you're doing. if ($_GET['u'] == '' || empty($_SESSION['user'])) { echo "You have not been given authorization to view this folder!"; } else { echo "<center><font color='00cc00' size='7'>Welcome back" . $_SESSION['user'] . "!</font></center>"; pgswtch($sp); } ?> Because I use a switch to generate a page layout similar to HTML frames without all the annoyances of frames, I was able to store the session_start() in the header.html file. It works perfectly this way across all pages accessed through the index.php page. The if statement is just a safegaurd that was in place to preven people from messing with the project. You could use it similarly to make sure the user session variable is actually recorded. In example: if(empty($_SESSION['user'])) { echo "No username has been indicated."; } If you do this and then see that message on the screen, then check the login verification that stores the data in the variable for a session_start(), as this needs to be on every page that uses session variables.
  8. I did that the first time around with the vardump, it's getting nulled regardless of the dump.
  9. If the page isn't embeded in another one that already has it, you need to include session_start(); before any of the page code. This tells the server you want to access the session information that you have stored elsewhere. I made a login thing for a section of my site that does what you're looking to do if you want to take a look at it.
  10. Line 8 of class file: $this->link = mysql_connect("localhost",$user,$pass); code for config file (info replaced with blank space): <?php $config = array( "user" => " ", "pass" => " ", "database" => " "); ?>
  11. It doesn't work because it then ignores the inclusion of the config file
  12. yes: and it errors at the query
  13. Okay, after adding it in several places, it would seem the second I'm inside the first function on list.php (tablestart), it's null...even before the "global $db;" line I see no reason for a function to cause this...
  14. Okay, I did that and because of my lack of formal education in PHP, I'm left scratching my head a bit further I'm assuming that one of the class functions is causing it to revert back to a NULL variable. Looking through my class file, my attention is drawn to the followig lines: protected $link; protected $lastResult; and function query($query) { $this->lastresult = mysql_query($query) or die('MySQL error: ' . mysql_error()); return $this->lastresult; } function fetch_array($result = false) { if(!$result) { return mysql_fetch_array($this->lastresult); } else { return mysql_fetch_array($result); } } So, the function cannot execute because the protected status is preventing the list.php code from making a new entry (for lack of a better term) using the class. Am I at least close to correct?
  15. Hello again! I've been trying out new things (well, new for me) in php again. This time I decided to try a real challenge and make a forum system. A friend suggested I use a class for all database functionalities. i was reluctant at first, but decided if I was going to try using classes for the first time, it might as well be with this. With some guiding help, I set up the files and gave it a visual once over to check for errors. Nothing seemed out of place, but when I loaded the page to try it out, I got this error: I didn't see anything out of line, so I consulted my friend about it. He made a few small adjustment suggestions, but nothing fixed the issue. I then bugged my host about it, and he couldn't find anything wrong either. Both people are highly experienced in php, so when they say it SHOULD be working I am left rather confused. Here is list.php: <?php include("db.class.php"); include("db.config.php"); $db = new databaseConnection($config['user'],$config['pass'],$config['database']); $g = $_GET['g']; $s = $_GET['s']; $t = $_GET['t']; function tablestart($a = '1') { global $db; echo "<table border='" . $a . "' cellpadding='10' cellspacing='0' align='center' width='80%' style='color: #C0C0C0'>\n"; } function contents($table, $a, $b = '1', $c = '1') { global $db; $db->query("SELECT * FROM $table"); while($row = $db->fetch_array()) { if($row['level'] <= $_SESSION['ulevel']) { echo "<tr><td width='5%'><!--indicator--></td><td width='80%'><a href='index.php?pg=h&g='" . $row['g']; if(($a > '1') && ($row['g'] == $b)) { echo "&s=" . $row['s']; if(($a > '2') && ($row['s'] == $c)) { echo "&t=" . $row['t']; } } } echo "' style='color: #C0C0C0 ; text-decoration: none'><font size='4'>" . $row['name'] . "</font><br /><fpnt size='3'>" . $row['desc'] . "</td><td width='15%'><!--last update--></td></tr>\n"; } } if(empty($_SESSION['ulevel'])) { $_SESSION['ulevel'] = '0'; echo "<font color='#CC0000'><center>You need to register to post in these forums.</center></font><br />\n"; } if(empty($g)) { tablestart(); contents('group', '1'); echo "</table>\n"; } elseif(empty($s)) { tablestart(); contents('section', '2', $g); echo "</table>\n"; } elseif(empty($t)) { tablestart('0'); echo "<tr><td width='80%'></td><td><!--new topic--></td></tr>\n</table>\n"; tablestart(); contents('topic', '3', $g, $s); echo "</table>\n"; } elseif(!empty($t)) { tablestart('0'); echo "<tr><td width='80%'></td><td><!--new topic and reply--></td></tr>\n</table>\n"; $data = file_get_contents('topics/g' . $g . 's' . $s . 't' . $t . '.txt'); $post = explode("<!--p-->", $data); $length = count($post); tablestart('1'); for($z = '0'; $z < $length; $z ++) { $i = '0'; $cont = explode("<!--e-->", $post[$pos]); echo "<tr><td><b>" . $cont[$i] . "</b><br /><!--future additions--></td><td>\n<table width='100%' style='font-size: xx-small'>\n<tr><td height='3' width='75%'>"; $i ++; echo "Posted on" . $cont[$i] . "</td><td height='3' width='25%'><!--future additions--></td></tr><tr><td width='100%'>"; $i ++; echo $cont[$i] . "</td></tr></table></td></tr>\n"; } echo "</table>\n"; } ?> My aim here was to have a single page to display the groups, sections, topics, and posts in order to keep database calls where I could find them easily. and here is the class file: <?php class databaseConnection { protected $link; protected $lastResult; function databaseConnection($user,$pass,$database) { $this->link = mysql_connect("localhost",$user,$pass); if( !$this->link ) { die('Vital information missing.'); } else { mysql_select_db($database,$this->link) or die('could not find database: ' . mysql_error()); } } function query($query) { $this->lastresult = mysql_query($query) or die('MySQL error: ' . mysql_error()); return $this->lastresult; } function fetch_array($result = false) { if(!$result) { return mysql_fetch_array($this->lastresult); } else { return mysql_fetch_array($result); } } } ?> I have tried everything from adjusting the php tags to putting the class directly in the page. The config file just provides the user, pass, and which database to connect to. I've checked it's formatting a few times just in case.
  16. *facepalm* once again I focus too much on the problem to see the cause. Thanks for pointing that out...and I did it again a few lines down, heh The page is working as it should *hug*
  17. Hello again! Seems I only ever come here when something goes wrong with my coding, heh Well, I've been experimenting with some code again, this time for a site to go along with my senior design project (hooray! BS degree almost complete!) error message: page code (with security information censored of course). Line 26 is the if statement checking for row['id'] matching <?php if (empty($_REQUEST['np'])) { $page = "home"; } else { $page = $_REQUEST['np']; } mysql_connect("localhost","user","pass") or die('could not connect: ' . mysql_error()); mysql_select_db("ck9_CHE175") or die('could not find database: ' . mysql_error()); $result = mysql_query("SELECT * FROM news") or die('could not find table: ' . mysql_error()); if ($page == "home") { echo "<font size='5'>Labor Improbus strives to keep information up to date. Select a news topic below to see what we have accomplished<br>"; echo "<table cols='1' align='center'>"; while ($row = mysql_fetch_array($result)) { echo "<tr><td><center><a href='index.php?pg=news&np=" . $row['id'] . "'>" . $row['title'] . "</a></center></td></tr> } } else { while ($row = mysql_fetch_array($result)) { if ($page == $row['id']) { echo "<center><font size='5'><b>" . $row['title'] . "</b></font></center><br><br>"; echo "<center><a href='index.php?pg=news&np=home'>[return to articles]</a></center><br><br>"; echo "<p>" . $row['body'] . "<br><br>"; echo "<center><a href='index.php?pg=news&np=home'>[return to articles]</a></center> } } } ?> When I used a similar if statement to check login information for an editing tool I made (thankfully that is funtioning as intended) it didn't have any problems. As always, I appreciate the help
  18. Sorry for the delay, was preparing for the GRE (got 1230 on it ) Thanks for the example, I think that's what I was trying to do (only a much better method). As always, you guys here are great help
  19. I think I understand now. Just to confirm: 1) it looks at what the file is 2) it makes sure the file is at "localhost" 3) if it is, it displays the file. Is that the gist of it? Does this go in the coding for the page that has the image on it, or another file like a dynamic image is? Sorry for how difficult it is to explain this to me, because I've learned mostly through experimenting with the coding I don't always understand the terminology associated with it.
  20. From what I read, you can use that to: force a download tell how many lines there are and what the last one is I don't see how that can be used to prevent other people from linking my site content to their site...Is there an example of it being used in this manner that I can look at and see if I can understand it better?
  21. *facepalm* Why do I keep missing these small errors? Thanks atomic, but that doesn't clear the error (and before someone comes along and mentions it, I did use session_start, but I forgot to type it in my original post, heh) PFM, not quite sure what you're saying. Most of what I know of PHP coding I've learned through reading the tutorials and experimenting with the functions they give me...this readfile() wasn't in the ones I read. Do you have a link that will explain it as well as showing an example of its use?
  22. I've been working on making my site less cluttered in the directories and more secure lately. In an attempt to prevent bandwidth theft from other people using images, I decided to switch all my site images to a dynamic image file. I've written a small test code to iron out as many bugs as I can BEFORE I impliment it fully. Code: <?php if ($_SESSION['i'] != "yes"} { $im = "theft"; } else { $im = $_GET['i']; } switch($im) { case 'theft": $image = imageCreateFromJPG('/theft.jpg'); break; case 'logo': $image = imageCreateFromJPG('/logo.jpg'); break; } imageJPG($image); imageDestroy($image); ?> When using it in the test copy of my site's index page (calling for the logo image) it works fine. When I try opening the page (with the GET['i'] set to logo, theft, and not set at all), I get the following error: I tried setting the current If...else as a long comment and re-writting it another way, but that didn't fix the issue. I tried looking up the error in the PHP manual, but the information presented wasn't helpful to me. Thanks in advance for any help you guys can provide (and the help here has always been great )
  23. Thanks everyone, just ran the full coding through a test and it works beautifully
  24. oops, lol Thanks for pointing that out, I wouldn't have remembered that for the life of me *hug* I can switch 'post' to 'get', right? I'm thinking it would be better to be able to refresh for updated information rather than going back to this page.
  25. <?php mysql_connect("localhost", user, pass) or doe(mysql_error()); mysql_select_db(database) or die(mysql_error()); $query = "SELECT * FROM monday"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo $row['name']; echo "<br />"; } echo "<form action="mash.php" method="post" target="blank">"; echo "Name 1:"; echo "<input name="name1" type="text" />"; echo " Name 2:"; echo "<input name="quantity" type="text" />"; echo "<input type="submit" />"; echo "</form>"; ?> I'm so far out of practice with PHP--due to a situation with my host and another person causing me to be unable to access my files for so long--that I can't remember how to solve this :/
×
×
  • 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.