Jump to content

genericnumber1

Members
  • Posts

    1,858
  • Joined

  • Last visited

    Never

Everything posted by genericnumber1

  1. thanks! wasn't thinking about variable scope.. [code] <?php class class2 { public function test2(){ $GLOBALS['class1']->test(); } } ?> [/code] did the trick ;) thanks so much!
  2. Can't seem to get two classes to work together! [b]test.class1.php[/b]: [code] <?php class class1 { public function test1(){ echo "worked!"; } } $class1 = new class1; ?> [/code] [b]test.class2.php[/b]: [code] <?php class class2 { public function test2(){ $class1->test1(); } } $class2 = new class2; ?> [/code] [b]test.php[/b]: [code] <?php require_once("test.class1.php"); require_once("test.class2.php"); $class2->test2(); ?> [/code] Running "test.php" yields: [b]Fatal error: Call to a member function test() on a non-object in[/b] [i][filepath][/i][b]test.class2.php on line 4[/b] Effects are the same if I define the classes in test.php as well. I'm sure it's a stupid mistake of mine, trying to do something php just doesn't like or something that just plain doesn't work.
  3. try something like this... [code]<?php $result = mysql_query("SELECT * FROM **** ORDER BY price ASC LIMIT 50"); $i = 0; while($row = mysql_fetch_array($result)){   ++$i;   // logic blah blah blah   if($i == 5){       echo "<br>";       $i = 0;   } } ?>[/code]
  4. as far as I'm aware $PHP_SELF isn't a predefined variable... $_SERVER['PHP_SELF'] is.. also your mysql error messages are a tiny bit off. instead of [code]mysql_query($sql, $conn) or die(mysql_error());[/code] it would be better as... [code]@mysql_query($sql, $conn) or die(mysql_error());[/code] and if you're saying something like... [code] <form action="<? $_SERVER['PHP_SELF'] ?>" method="post"> <input type="text" name="test" value="test"> <input type="submit"> </form> <?php if(isset($_POST['test'])){   echo "post worked!"; } ?> [/code] doesn't work then you might wanna look into a server error... (maybe browser error? so very doubtful)
  5. why not just combine password verification and password change into one? the change password form... [code] <form action="changepass.php" method="post"> Old Password: <input type="password" name="oldpass"><br> New Password: <input type="password" name="newpass1"><br> Repeat New Password: <input type="password" name="newpass2"> <input type='submit'> </form> [/code] changepass.php... [code] <?php $oldpass = md5($_POST['oldpass']); $newpass1 = md5($_POST['newpass1']); $newpass2 = md5($_POST['newpass2']); if($newpass1 != $newpass2){   // error action } $result = mysql_query("SELECT password FROM employees WHERE employeeid='$employeeid' LIMIT 1"); $row = mysql_fetch_array("$result"); if($row['password'] != $oldpass){   // error action } else {   if(@mysql_query("UPDATE employees SET password='$newpass' WHERE employeeid='$employeeid'")){       // success action   } else {       // error action   } } ?> [/code] just threw it together real fast so no guarantee as to if it works precisely, and it assumes you already defined $employeeid and established a mysql connection, but you get the gist of the logic eh?
  6. assuming that "itemId" is always going to be an integer you might wanna type cast it for security (ebil sql injection!) [code]$id = $_GET['id'];[/code] would be safer as [code]$id = (int)$_GET['id'];[/code] always nicer to be paranoid ;D
  7. It's all just html fun at the point you get the variables from the table... You said you had no problem getting the values from the table so I can assume that you just need insight on how to style it? Just plug the variables into fancy html/css! [code] $result = mysql_query("SELECT * FROM table"); while ($row = mysql_fetch_array($result)) { $imageurl = $row['imageurl']; $title = $row['title']; $author = $row['author']; $date = $row['date']; $description = $row['description']; echo " <div class='container'> <div class='image'><img src='$imageurl' alt='image' /></div> <div class='title'>$title</div> <div class='author'>$author</div> <div class='date'>$date</div> <p class='description'> $description </p> </div>"; } [/code] then you would just define the styles for the classes... you could use style tags instead of the classes in the above example... there really isn't much to it... an example of your css file could be like... [code] .container { clear:both; border-bottom:1px solid #000000; } .image { float:left; padding:3px; border:1px solid #000000; } .title { font-weight:bold; } [/code] of course there would be more stylings... but your issue isn't near as much PHP as it is html/css tinkering.
  8. Title says it all, is there a way to get the directory that an included file is in? Right now if I'm including the file "foo.php" I'd have to substr(__FILE__, 0, -7) to get the dir... is there a different way?
  9. Hey, I'm trying to pull some information from a string using regex, nothing TOO hard. I just figure I have my regex pattern wrong, hopefully that's what it is or I'm in the wrong forum. (this is of course not my real code, but it works the same way) [code] <?php $r = 1; $information = ' blah //startcode1 $code = "blah blah blah blah ";//endcode1 blah '; ?> [/code] I'm trying to just pull out the part that starts with //startcode1 $code = " and ends with ";//endcode1 Here is my method... [code] <?php preg_match('/(\/\/startcode'.$r.'\n\$code = )["\'](.*)["\'](;\/\/endcode'.$r.')/s', $information, $matches); ?> [/code] yet when I print_r() the $matches, there is nothing.... help >.>?
  10. php_value register_globals off I think that's it for a .htaccess... I dont know how to edit your php.ini on godaddy though, sorry.
  11. I'm not totally sure what you are interested in doing. Do you mean you wish for the script to look at a cookie (like for a username) and then post all the information for that username from a mysql table? If so... [code] <?php $username = $_COOKIE['username']; // Get the username mysql_connect("--host--", "--username--", "--password--"); // Connect to the database mysql_select_db("--database--"); // Select the database $query = "SELECT * FROM table_name WHERE username='$username' LIMIT 1"; // Set the query to pick only one row where the username matches the cookie username (insecure) $result = mysql_query($query); // Query the database $row = mysql_fetch_array($result, MYSQL_ASSOC); // Get the information from the $result resource and put it in the $row array // Set some variables to the $row array $email = $row['email']; $favoritecolor = $row['favcolor']; // Display the information echo "   Email: $email <br>   Favorite Color: $favoritecolor"; ?> [/code] (That will only display one row of information) To display the multiple rows... (not based on username or anything) [code] <?php mysql_connect("--host--", "--username--", "--password--"); // Connect to the database mysql_select_db("--database--"); // Select the database $query = "SELECT * FROM table_name"; // Set the query to select everything from the table $result = mysql_query($query); // Query the database while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { // Loop through all the rows   // Set some variables to the $row array   $username = $row['username'];   $email = $row['email'];   $favoritecolor = $row['favcolor'];   // Display the information   echo "       Username: $username <br>       Email: $email <br>       Favorite Color: $favoritecolor <br><br>"; } ?> [/code] it's not secure though, and definately not clean... Oh yes, visit these as well... http://www.phpfreaks.com/forums/index.php/topic,95441.0.html - MySQL Data Retrieval http://www.phpfreaks.com/forums/index.php/topic,95443.0.html - MySQL Data Retrieval (Advanced) EDIT: put in comments... for the heck of it
  12. I stripped out every little thing except for the bare minimum (in an attempt to pull out anything that would refresh the page) and now it is only posting one log, but it doesn't have the referrer in it... I'm not just being an idiot and assuming that if I visit "alkknfelakn.php" my browser will send that as the referrer to 404.php when that's not how it works am I? EDIT: Sorry, I'm tired and I just thought "Wait.... it's a header redirect so it's not gonna have the requested page, CRAP!" So yeah, now that I've sounded quite stupid I'd like to say thanks for helping me, I'll just use the referrer to see what page had the broken link in it..
  13. Well, when I dumped $_SERVER I didn't notice anything odd, the referer was there etc... Proposed diagnosis: Server is tweaking out. EDIT: I originally was testing the REFERER with a link on the 404.php page, I tried actually being redirected to the 404.php from "flakneflkanfe.php" (obviously it wasnt there) but the log still posted 404 ERROR - - 09/12/06 Username: Generic IP Address: -edited- User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6 404 ERROR - http://www.url.com/404.php - 09/12/06 Username: Generic IP Address: -edited- User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6 So do you think it's a good diagnosis that for some reason it doesn't get the referrer when it is redirected to 404.php by the .htaccess file and when it gets to 404.php it posts a value with a blank referrer, then for some reason the page reloads and posts that it was referred to by 404.php?
  14. [b]What the script is supposed to do[/b] It's a custom error page (404) and it basically just logs the missing page, and some other information. I'm seeing this as perhaps being a server problem? It's been driving me crazy. [b]The Script[/b] [code] <?php $pageref = $_SERVER['HTTP_REFERER']; // (Not REFERRER) $date = date("m/d/y"); $error = "<b>404 ERROR - $pageref - $date</b><br>"; $error .= "Username: " . htmlentities($_COOKIE['u']) . "<br>"; $error .= "IP Address: " . $_SERVER['REMOTE_ADDR'] . "<br>"; $error .= "User Agent: " . htmlentities($_SERVER['HTTP_USER_AGENT']) . "<br><br>"; $handle = fopen("logs/zomgerrors.htm", "r+"); fwrite($handle, $error); ?> [/code] [b]Display the missing page[/b] [code] <?php echo "(" . $pageref . ")"; ?> [/code] [b]The Problem[/b] [list] [*]When I echo $pageref, it is always blank or "()" [*]When it writes to the log it always writes twice, one of them without the $pageref [/list] [b]A Single Log Example[/b] 404 ERROR - - 09/12/06 Username: Generic IP Address: -edited- User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6 404 ERROR - http://www.url.com/missingpage.php - 09/12/06 Username: Generic IP Address: -edited- User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6
×
×
  • 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.