Jump to content

tpl41803

Members
  • Posts

    42
  • Joined

  • Last visited

    Never

Everything posted by tpl41803

  1. as always thanks for the quick response this does help me optimize the code a little but doesn't solve my problem entirely if i change my isset statement to reflect what you've posted i will be able to get the error page, but it will prevent me from viewing any of the other pages on my site (about 10 static pages -- index, cover, contents, etc...) As far as I can see the problem is that when a bad link comes across (/whatever.php) it forwards it directly to the home page instead of ?p=error&err=404, which is what I want it to do and I can't figure out why it's not posting this properly.
  2. Hey all I built a site a while back with custom error pages that used one php file (error.php) which contained a list of php error messages, the .htaccess file redirected all errors to this file and passed the error through the url in a variable that my error page would request. It worked perfectly. Now, I've created the same thing, but I am using a much more complex (for me) site and the errors arn't working correctly. Here's the gist of my error.php: <?php $error = $_REQUEST['err']; if ($error == 404) { $errorText = 'Document not found. Please check the URL and try again.'; } elseif ($error == 206) { $errorText = 'Partial content.'; } elseif ($error == 301) { $errorText = 'Document moved permanently.'; } elseif ($error == 302) { $errorText = 'Document found in another location.'; } elseif ($error == 400) { $errorText = 'Bad request'; } elseif ($error == 401) { $errorText = 'Authorization required to access the requested area.'; } elseif ($error == 403) { $errorText = 'Access forbidden.'; } elseif ($error == 408) { $errorText = 'Request timed out. Please try again.'; } elseif ($error == 500) { $errorText = 'Internal server error'; } elseif ($error == 501) { $errorText = 'Request type not supported'; } else { $errorText = 'An unknown error has occurred.<br /><br />If you reached this site via a bookmark, please note that the addresses of all pieces on this site changed in July 2010 and bookmarks must be updated to reflect our new format. We apologize for the inconvenience.'; } ?> <div id="content"> <h2>Error <?php echo $error; ?></h2> <br /><br /><br /> <p><?php echo $errorText; ?></p> </div><!-- #content --> The relevant portion of the .htaccess file: Options -Indexes ErrorDocument 206 /?p=error&err=206 ErrorDocument 301 /?p=error&err=301 ErrorDocument 302 /?p=error&err=302 ErrorDocument 400 /?p=error&err=400 ErrorDocument 401 /?p=error&err=401 ErrorDocument 403 /?p=error&err=403 ErrorDocument 404 /?p=error&err=404 ErrorDocument 408 /?p=error&err=408 ErrorDocument 500 /?p=error&err=500 ErrorDocument 501 /?p=error&err=501 Now, my index doc is a list of includes depending on which page is requested. So I have a piece of code like this at the beginning of the doc to get this information: if (isset($_GET['p'])) { $p = $_GET['p']; } else { $p = index; } Finally I call the actual pages through includes and etc: if ($p == index) { require "includes/menu.php"; require_once "pages/index.php"; } elseif ($p == error) { require "includes/menu.php"; require_once "pages/errors.php"; } I don't know if this is a tremendously confusing construction or not, it makes perfect sense to me. I am not a PHP pro (I always feel I need to explain this here). I've read books and gotten help here and taught myself through trial and error. I think my issue is in the isset line and the .htaccess not actually posting the information in the url. If I remove the isset I can get the errors to display, but only an "unknown error," I can never get a 404 to appear as intended. Any ideas what the hell I'm doing wrong / should be doing greatly appreciated thanks again
  3. ah that's exactly what i needed, thanks so much :-D
  4. seems this is the issue, i have broken my script into 2 separate pages, each uploads 20 files at a time, this is not EXACTLY what I was looking for, but it will do until I can find away to override what seems to be a 20 file maximum I've looked through the php.ini settings to see if there is a way to change it but it seems like there isn;t thanks for all your help :-D
  5. that's more or less what I am encountering but I am not receiving the error i guess that means that you can only upload 20 files at a time?
  6. well this is interesting, when i print_r($_FILES) i get an array that counts 0-19. It should be counting 0-39.
  7. I have been playing with the script a little and adding some checks into the code and this new version produces the exact same problem, example: if (!empty($_FILES['ufile']['tmp_name'][0])) { if (!copy($_FILES['ufile']['tmp_name'][0], $path0)) { echo "failed to save '.$path1.'"; } echo "'.$path0.' was saved <br /><br />"; } else { echo "'.$path0.' was empty <br /><br />"; } Now, when I upload the first 20 files, i receive "XXXX was saved" and 21-40 returns "XXXX was empty" DOES php only allow the userfile array only count to 20? I'm not sure if this is really the issue, because if i only upload the 21st file, for example, the script still returns "XXXX was empty" for number 21. not sure :-/
  8. yes i do get error messages when i make syntax errors and things so i know error messages are turned on
  9. added but the result is the same and i don't get any errors reported :-/
  10. Hey all I have an issue with a really bare file uploading script which is supposed to upload up to 40 files at the same time, rename them, and save them to a predetermined directory. My code on a page called PHOTOS looks like this (shortened because it's the same thing repeated for each input): <form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="destination" value="$row['folder']" /> 1. <input name="ufile[]" type="file" id="ufile[]" /><br /> 2. <input name="ufile[]" type="file" id="ufile[]" /><br /> 3. <input name="ufile[]" type="file" id="ufile[]" /><br /> 4. <input name="ufile[]" type="file" id="ufile[]" /><br /> etc... and my php action, "upload.php" looks like this: $destination = $_POST['destination']; $path1= "../sales/inventory/$destination/". "1.jpg"; $path2= "../sales/inventory/$destination/". "2.jpg"; $path3= "../sales/inventory/$destination/". "3.jpg"; $path4= "../sales/inventory/$destination/". "4.jpg"; etc.... if (!empty($_FILES['ufile']['tmp_name'][0])) { copy($_FILES['ufile']['tmp_name'][0], $path1); } if (!empty($_FILES['ufile']['tmp_name'][1])) { copy($_FILES['ufile']['tmp_name'][1], $path2); } if (!empty($_FILES['ufile']['tmp_name'][2])) { copy($_FILES['ufile']['tmp_name'][2], $path3); } if (!empty($_FILES['ufile']['tmp_name'][3])) { copy($_FILES['ufile']['tmp_name'][3], $path4); } etc... I'm sure there are prettier ways of doing this, but it works fine until I upload a 21st files. The script for some reason will only save the first 20 files to the destination directory. I have changed the max file upload size to reflect the amount of bytes I am passing through this script (which is rarely more than 4.5mb). Any ideas why this might be happening? Thanks a lot, always appreciate the help I get when i come here!
  11. i think i have most of my issue figured out, thanks so much for your help i'm sure ill be back with a problem sooner or later -- it's all in practice i suppose thanks again
  12. I don't believe so-- the only issue I can really see is that I am using *'s for nearly all my queries, even if I am only looking for one row. is FROM $table not necessary? I was under the impression that that was necessary on each query or else the script won't know what's going on.
  13. I'm not sure I completely follow you. I follow the * part and I'm going to rewrite the majority of my queries. There are a great many instances where I am using a * and actually only looking for one row of info. So there's some freed memory right there. I'm not sure I'm following the rest of your reply though. By "not necessary to query the location" do you mean the FROM $table isn't necessary? And I have looked into joins in the past but never successfully wrote a join that worked. I think the concept of joins as a whole just eludes me.
  14. thanks for the quick response i've gone through my pages and removed a few extra connections that I didn't realize were unnecessary and although you say it's not entirely necessary I added a mysql_close() at the end of the connections that I am using. I'm not sure what you mean by rewriting the queries so that more of the data processing can be done on mysql's side though. My normal query will look something like this: $result = mysql_query("SELECT * FROM $table $where"); if (!$result) { die("Query to show fields from table failed"); } I'd appreciate it if someone could provide me with a quick example of how to rewrite this to save memory Thanks again!
  15. Hi all I hope I'm posting this in the right place -- I've been looking around on these forms and others and I can't seem to find the answer to my question. I have no real training in php / mysql / etc... Everything I know I have learned through online guides and these forms SO--what, generally, are some good practices for saving memory. I have put together a site that relies heavily on mysql queries -- I may have 10-15 on a single page. I am becoming increasingly worried about the amount of memory and connections I have opened and I am not entirely sure how this works. For example, if I run a query, is it absolutely necessary for me to free the result at the conclusion of the script? I am somewhat under the impression that once the script is executed the result is automatically freed and the connection is closed, but then I am not entirely certain of this. Today I had an issue with my site where every page was loading a "the connection has been reset" error -- I encountered this error when attempting to access the filemanager also. Is this because I have not been freeing my results and closing my connections? Any advice / help greatly appreciated Thnanks
  16. thanks so much, this is exactly what i needed :-D
  17. Hi all, I am working on a building a search page which will allow me to search and browse through a database by any of its columns. There are 10 columns total and I want to be able to search by any combination of them. I started with just three variables to see if I could figure it out. And after completing that script, I realize writing the script for 10 variables will be enormous. if (isset($bmake, $btype, $bprice)) { if ($bmake == all && $bprice == all && $btype == all) { $where = ""; } elseif ($bmake == all && $bprice == all && $btype != all) { $where = "WHERE style='$btype'"; } elseif ($bmake == all && $bprice != all && $btype == all) { $where = "WHERE price BETWEEN '$priceLow' and '$priceHigh'"; } elseif ($bmake != all && $bprice == all && $btype == all) { $where = "WHERE make='$bmake'"; } elseif ($bmake == all && $bprice != all && $btype != all) { $where = "WHERE style='$btype' AND price BETWEEN '$priceLow' and '$priceHigh'"; } elseif ($bmake != all && $bprice == all && $btype != all) { $where = "WHERE make='$bmake' AND style='$btype'"; } elseif ($bmake != all && $bprice != all && $btype == all) { $where = "WHERE make='$bmake' AND price BETWEEN '$priceLow' and '$priceHigh'"; } elseif ($bmake != all && $bprice != all && $btype != all) { $where = "WHERE make='$bmake' AND style='$btype' AND price BETWEEN '$priceLow' and '$priceHigh'"; } } else { $bmake = 'all'; $btype = 'all'; $bprice = 'all'; $where = ''; } $result = mysql_query("SELECT * FROM $table $where ORDER BY year"); if (!$result) { die("Query to show fields from table failed"); } So, my problem now is that if I add another variable, I have to write a whole lot more elseif statements, for the total 10 variables the number of combinations is well into the thousands. I'm not math expert, that's just a guess. I know this is possible because there are hundreds of sites in existence that function in the way that I want mine too. Anyone have any ideas or steps in the right direction? I'm using PHP5.2 thanks
  18. I am trying this: if ($row['mileage'] == 0) { $mileage = 'Call for Mileage'; } else { $mileage = number_format($row['mileage']); } But it doesn't seem to work properly. It changes everything to "Call for Mileage" rather than just the ones that equal 0
  19. Obviously I've worded my title poorly. I am trying to write a script that will change outputted data conditionally. For example, I have a website that displays the inventory of a used car lot. Frequently, especially with older vehicles, we do not have mileage information. So, as far as the database is concerned the mileage = 0. However, when I output that data on the page I don't want the Mileage to be displayed as 0, I want to display something like "Call for Mileage." I currently have all the mileage information saved in a Int(20) field in my database, otherwise I would just have that data saved directly into the database. Is this even possible? I've tried a few different things, but it doesn't seem to be working. Can anyone point me in the right direction? Thanks!
  20. Yes I work on windows. At the moment I am just working on my local server (apache). I'm not much of a programing guru so I downloaded the pre-packaged executables for windows (both Apache, PHP, and now postgres). I hadn't thought to try to re-install php, I can give that a shot. But when I installed it I don't remember any settings choices during the installation.
  21. I'm just learning my way around PHP! Everything I haven't been able to figure out you guys have helped me with. I've decided that flatfile databases won't work for the projects I've been asked to work on recently so I am trying out Postgresql -- I had a really hard time working with MYSQL, I just didn't understand how it was working about a year ago when I tried it out. Postgresql seems to be pretty straightforward and I have gotten it installed onto my server. HOWEVER, when I run any php scripts, it doesn't seem to be working. I have determined that my installation of PHP doesn't have postgresql enabled or activated. I have searched around (both here, on other forums, and websites) and I can't figure out how to get it working properly. my php.ini, I believe, has it enabled properly: I added this line under DYNAMIC EXTENSIONS (according to a tutorial I found somewhere) extension=php_pgsql.dll and the PostgreSQL section looks like this (haven't made any changes) [PostgresSQL] ; Allow or prevent persistent links. pgsql.allow_persistent = On ; Detect broken persistent links always with pg_pconnect(). ; Auto reset feature requires a little overheads. pgsql.auto_reset_persistent = Off ; Maximum number of persistent links. -1 means no limit. pgsql.max_persistent = -1 ; Maximum number of links (persistent+non persistent). -1 means no limit. pgsql.max_links = -1 ; Ignore PostgreSQL backends Notice message or not. ; Notice message logging require a little overheads. pgsql.ignore_notice = 0 ; Log PostgreSQL backends Notice message or not. ; Unless pgsql.ignore_notice=0, module cannot log notice message. pgsql.log_notice = 0 Everything I have found tells me I need to enter ./configure --with-pgsql Into the PHP configuration script, but I can't for the life of me figure out where to enter this. Please help :-D
  22. Hey everyone, I've been searching endlessly for a pagination script that will work exactly how I want it to. I dont understand PHP well enough to write my own from scratch so I've been working with a few others. The current script I'm using allows me to sort my database by different columns / fields, but I can't get it to paginate and then I came across a script to paginate--here on these forms at http://www.phpfreaks.com/forums/index.php/topic,245920.0.html--but I can't get it to sort my data. my current, paginated code looks like this: <?php $Page = (int)(!empty($_GET['page']))?$_GET['page']:1; $Entries = 5; $logfile = "inventory.txt"; if (file_exists($logfile)) { $handle = fopen($logfile, "r"); $log = fread($handle, filesize($logfile)); fclose($handle); $fulllog = file($logfile); } else { die ("The log file doesn't exist!"); } $log = explode("\n", trim($log)); $NumRecords = count($fulllog); $totalPages = ceil($NumRecords/$Entries); $end = $Entries*$Page; $start = $end-$Entries; $end = ($end > $NumRecords)?$NumRecords:$end; $log = array(); for ($i = $start; $i < ($end); $i++) { $log[$i] = trim($fulllog[$i]); $log[$i] = explode('|', $fulllog[$i]); } ?> <?php require_once('head.php'); ?> <div id="content"> <ul class="sort"> <?php echo '<li>'. count($fulllog) .' vehicles found</li>'; // create first page link if($Page>2) { echo '<li><a href="'.$_SERVER['PHP_SELF'].'?page='.($Page==1).'"><< First</a></li>'; } else { echo '<li><< First</li>'; } // create previous link if($Page>1) { echo '<li><a href="'.$_SERVER['PHP_SELF'].'?page='.($Page-1).'">< Prev</a></li>'; } else { echo '<li>< Prev</li>'; } // create intermediate links for ($n = 1; $n <= $totalPages; $n++) { echo "<li><a href='?page=".$n."' >$n</a></li>"; } // create next link if($Page<$totalPages) { echo '<li><a href="'.$_SERVER['PHP_SELF'].'?page='.($Page+1).'">Next ></a></li>'; } else { echo '<li>Next ></li>'; } // create last page link if($Page<$totalPages && $Page!=($totalPages-1)) { echo '<li><a href="'.$_SERVER['PHP_SELF'].'?page='.($totalPages).'">Last >></li></a>'; } else { echo '<li>Last >></li>'; } ?> </ul> <?php foreach ($log as $logline) { if ($logline['1'] == '') { echo ' <div id="container"> <a href=' . $logline['1'] . '><img src="inventory/thumbs/' . $logline['0'] . ' alt="' . $logline['2'] . '" title="' . $logline['2'] . '" /></a> <h2><a href=' . $logline['1'] . '>' . $logline['2'] . '</a></h2> <ul> <li><b>Year:</b> ' . $logline['3'] . '</li> <li><b>Make:</b> ' . $logline['4'] . '</li> <li><b>Model:</b> ' . $logline['5'] . '</li> <li><b>Color:</b> ' . $logline['7'] . '</li> </ul> <ul class="right"> <li><b>MPG <small>[City/Hwy]</small>:</b> ' . $logline['6'] . '</li> <li><b>VIN:</b> ' . $logline['8'] . '</li> <li><b>Price:</b> $' . $logline['9'] . '</li> <li><b>Comment:</b> ' . $logline['11'] . '</li> </ul> </div> '; } else { echo ' <div id="container"> <a href=' . $logline['1'] . '><img src="inventory/thumbs/' . $logline['0'] . ' alt="' . $logline['2'] . '" title="' . $logline['2'] . '" /></a> <h2><a href=' . $logline['1'] . '>' . $logline['2'] . '</a></h2> <ul> <li><b>Year:</b> ' . $logline['3'] . '</li> <li><b>Make:</b> ' . $logline['4'] . '</li> <li><b>Model:</b> ' . $logline['5'] . '</li> <li><b>Color:</b> ' . $logline['7'] . '</li> </ul> <ul class="right"> <li><b>MPG <small>[City/Hwy]</small>:</b> ' . $logline['6'] . '</li> <li><b>VIN:</b> ' . $logline['8'] . '</li> <li><b>Price:</b> $' . $logline['9'] . '</li> <li><b>Comment:</b> ' . $logline['11'] . '</li> </ul> </div> '; } } ?> </div> <?php require_once('foot.php'); ?> the script works perfectly, I just can't figure out how to sort it by fields. I've tried several different things and basically exhausted my own abilities, just wondering, really, if anyone has any suggestions to a guide that would walk me through it, or something along those lines. Thanks :-D
  23. great! managed to get it working and as far as i can tell working correctly! i moved the variables into my processing file (sign_in.php) and everything now works as intended i really appreciate your patience with me :-D
  24. duh... thanks so much! okay, so I would need to do something like <?php session_start(); $_POST['user_name'] = $user_name; $user_name = $_SESSION['user_name']; ?> and then on the subsequent pages the $_SESSSION['user_name'] should work correctly? or am i wrong?
  25. OH, I misunderstood... Contents of the required head file--"head.php" <?php session_start(); $_SESSION['user_name'] = $_POST['user_name']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>title</title> <link rel="stylesheet" type="text/css" href="style.css" /> <!--[if IE]> <link rel="stylesheet" type="text/css" href="iestyle.css" /> <![endif]--> </head> <body> <div id="nav_right"> <?php echo $_SESSION['user_name']; ?>| <a href="#">settings</a>| <a href="#">help</a>| <a href="index.html">sign out</a> </div> </div> contents of the actual page (which calls this require) -- this is "index.php" <?php require("head.php"); ?> <div id="page"> <div id="content"> <?php require("sub_head.php"); ?> <?php require("actions.php"); ?> <?php require("mail.php"); ?> <?php require("actions.php"); ?> </div> </div> </body> </html>
×
×
  • 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.