-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
Is there anything interesting ABOUT what the actual values are that would help pin down if this might be a bug or a limitation with the database driver or with php? Are all the actual values (that come out as zero using php code) all greater than some value, while all the values that work are all less then some value? Is the code that you posted all the code that duplicates the problem, in case you have some code that contains a logic error or is doing some math on the value that chokes under some conditions? Any chance that your page is being requested twice by browsers and the second time the $agent is empty and you see the zero result of that? I would recommend logging the actual query every time the page gets requested so that you can see a record of every query that gets executed. See the error_log function to log the $sql variable to a file.
-
^^^ The problem with posting links to scripts is there is no way to tell if they meet the requirements that the OP is looking for (the best person to find a script that meets all their requirements is the person looking for the script.) Also, there are just a HUGE amount of outdated and insecure php scripts posted all over the Internet where the only concern of the site posting them is revenue from ads and links you might click on while visiting the site. @Rifts, the link you posted has the following problems and should not be used as is - 1) The passwords are not hashed/encrypted when stored in the database. That site only suggests hashing the passwords by including a link near the end of that page. 2) The script is 8+ years out of date (use session_register and session_is_registered instead of $_SESSION variables) and won't work on most current php installations. 3) The code is unconditionally using stripslashes() on the form data without testing if the setting that would require that step to be performed is ON. 4) The code is inconsistently using some short open tags along with full open tags. Only full open tags should be used in any code, especially code posted as being a 'guide' to doing anything in php, to insure you don't waste time trying to get it to work on any particular server or when moving to a different server. 5) The code that is to be put on any page to test if the current visitor is logged in, is not secure because there is no exit;/die; statement after the header redirect to prevent the 'secured' content on the page from being accessed. Any hacker can bypass the login check code and access the protected page. 6) The tutorial incorrectly implies that for php5 you must do something different to one part of the code.
-
Before you go further, please set error_reporting to E_ALL and display_errors to ON in your master php.ini. Stop and start your web server to get any changes made to the master php.ini to take effect and confirm that the two settings actually got changed by using a phpinfo(); statement (in case the php.ini that you changed is not the one the php is using.) Doing this will get php to point out errors that will save you a ton of time. Specifically the non-existent $result variable that Pikachu2000 pointed out would have result in an error and your current problem of using mysql_real_escape_string() before you have a connection to the mysql server would result in an error that would call your attention to what is wrong.
-
"Couldn't fetch mysqli" error, but connection isn't closed
PFMaBiSmAd replied to karin's topic in PHP Coding Help
@phpsort, Database connections are resources and are automatically destroyed when the processing on any page request ends. You must create a new connection on each page request (or get one of the available persistent connections on each page request.) -
With the following code in sample.php, what do you get when you browse directly to sample.php?id=42 <?php ini_set("display_errors", "1"); error_reporting(E_ALL); require("sys/functions.php"); dbConnect(); $id = $_GET["id"]; if(!isset($id)) { echo "select an ID"; } else { $res = mysql_query("SELECT * FROM gallery where id=$id"); $row = mysql_fetch_assoc($res); // header("Content-type: image/$row[extension]"); echo $row['image']; } ?>
-
Why in the hell is mysql_select_db undefined?
PFMaBiSmAd replied to tibberous's topic in PHP Installation and Configuration
What method did you use to install php? Manually with the .zip package or using the .msi installer package? -
You need to troubleshoot and narrow down any common conditions that apply to the email addresses that A) Receive the email but put it into the junk/spam folder and B) Don't receive the email at all. Are they at one or a few receiving domains? Is this constistant, any particular receiving email address always puts the email into the junk/spam folder or any particular receiving email never receives the email. You should also check your sending mail server log files to determine what if any information you can find out about what your mail server did with the the specific emails that are not working or status your mail server got back from the receiving mail servers.
-
URGENT: how to block access to php code?
PFMaBiSmAd replied to king.oslo's topic in Apache HTTP Server
Another possibility is if you are using short open tags <? in the code that simply being output instead of being seen as php code. -
URGENT: how to block access to php code?
PFMaBiSmAd replied to king.oslo's topic in Apache HTTP Server
The php language engine is either specifically disabled for those folders or it was never enabled for those folders. Are there any .htaccess files that have statements in them with any php language related settings that could be disabling php in those folder(s)? Do any of the httpd.conf and related apache configuration files have any conditional statements that only enable the php language in specific folder(s), such as your document root folder? Short answer: You need to investigate the configuration settings on your server to find out either why php is only enabled in certain folders or to find out why it is disabled in other folders. -
checking to see if there is a allready that result in mysql
PFMaBiSmAd replied to Jragon's topic in PHP Coding Help
If you troubleshoot what it is doing, you will find that the 'SET' keyword is not used in that syntax. -
checking to see if there is a allready that result in mysql
PFMaBiSmAd replied to Jragon's topic in PHP Coding Help
Is ip_address defined as a unique key so that the ON DUPLICATE KEY logic has something to test? You also forget to write in your post what "doesn't work" means. -
You are mixing a mysqli database connection with mysql_ function calls. You cannot mix mysqli and mysql statements on a single connection.
-
checking to see if there is a allready that result in mysql
PFMaBiSmAd replied to Jragon's topic in PHP Coding Help
Seriously Jragon, if you got an error message telling you there was no column named 'number', a person posted that you did not have a column named 'number', and your own table definition shows that there no column named 'number', just what level of help are you expecting from a forum? As to the question of what would an INSERT... ON DUPLICATE KEY UPDATE ... query look like - $query = "INSERT INTO logged_ips (ip_address, ip_visits) VALUES ('$ip',0) ON DUPLICATE KEY UPDATE SET ip_visits = ip_visits + 1"; mysql_query($query, $connection); Edit: The reason your queries don't do anything is because you don't add a value in sql using ++1 the way you are trying to do. -
checking to see if there is a allready that result in mysql
PFMaBiSmAd replied to Jragon's topic in PHP Coding Help
You can replace all three of those queries with a simple - INSERT ... ON DUPLICATE KEY UPDATE ... query. -
Temporarily comment out the header() statement and add the following two lines right after your first opening <?php tag in sample.php - ini_set("display_errors", "1"); error_reporting(E_ALL); I also recommend that you post the code that uploaded and inserted the file into the database.
-
It would help if you posted an example of the time column data values, the actual result, and the expected result. Just telling us that it doesn't work, doesn't convey any useful information.
-
While it might not be the only problem preventing your image from working, as already stated, the content type for a .jpg is not image/jpg, it's image/jpeg Edit: If your browser indicates the size of the output is the expected value, it is likely that using the correct Content-type: will fix the problem.
-
The code that has been posted is valid (with some assumptions and crossed fingers), so it is a matter of troubleshooting what it actually is doing or not doing.
-
What exactly does $row[extension] contain, because there are only a few Content-type: image/ values where the actual file extension IS a valid Content-type? What do you get when you browse directly to sample.php?id=42 ??? If you get a blank screen when you do that, what does a 'view source' in the browser show? Are you doing this on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php errors would be reported and displayed?
-
I would reverse the order of the two arguments (it calculates datetime_expr2 – datetime_expr1.)
-
You can simply calculate the differences in your query and then use the information any way you want when you display it (i.e. if days are zero, display the hours...) - SELECT TIMESTAMPDIFF(HOUR,now(),your_datetime_column) as hours, TIMESTAMPDIFF(DAY,now(),your_datetime_column) as days
-
Cannot Redeclare Previously Declared Function
PFMaBiSmAd replied to objnoob's topic in PHP Coding Help
Either your code is including/requiring the function definitions more than once OR you have the function definitions inside of a loop. You might also have multiple files with the same function definitions in different folders. Php has also had a lot of problems getting the _once versions of the require/include to actually detect that when it is including the same file. I recommend posting the error message and enough of the relevant complete code that produces the problem so that someone can help. -
If you already have an active thread for THIS PROBLEM, don't start another one. This will get you closer (I also removed the duplicate code producing the pagination links since the top and bottom is the same. Just echo the values you already have.) - <?php require_once('../../Connections/Test.php'); // Make a MySQL Connection mysql_select_db($database_Test, $Test); // How many rows to show per page $rowsPerPage = isset($_GET['rpp']) && $_GET['rpp'] > 0 ? (int)$_GET['rpp'] : 25; // use $_GET['rpp'] or a default of 25 // if the records per page form is submitted, process it and set the $rowsPerPage to the new value if(isset($_POST['SUB'])){ // form was submitted $rowsPerPage = (int)$_POST['records_per_page']; } $rpp = "&rpp=$rowsPerPage"; // add this get paraemter to the links // Show the first page by default $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // Counting the offset to show the right records per page $offset = ($pageNum - 1) * $rowsPerPage; // Retrieve all the data from the seasons table $query = "SELECT *, DATE_FORMAT(`season_start`,' %D %M %Y') AS startdate, DATE_FORMAT(`season_end`,'%D %M %Y') AS enddate FROM seasons "; $query .= "LIMIT $offset,$rowsPerPage"; $result = mysql_query( $query ) or die('Query: ' . $query . '<br>Produced error: ' . mysql_error() . '<br>'); //Query for the DECADES INDEX at the top $links = mysql_query("SELECT DISTINCT SUBSTRING(season_name,1,3) as letter FROM seasons ORDER BY 1") or die(mysql_error()); // PAGINATION // Find the number of records $page_query = "SELECT COUNT(season_name) AS numrows FROM seasons"; $page_result = mysql_query($page_query) or die('Error, query failed'); $page_row = mysql_fetch_array($page_result, MYSQL_ASSOC); $page_numrows = $page_row['numrows']; // Divide the number of records by records per page to get number of pages $maxPage = ceil($page_numrows/$rowsPerPage); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Season List</title> <link href="../../styles/databaseedit.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="container"> <?php include("/homepages/46/d98455693/htdocs/Templates/database/header.html"); ?> <?php include("/homepages/46/d98455693/htdocs/Templates/database/left.html"); ?> <div class="content"> <h1> SEASON LIST</h1> <p>Filter by Decade<br /> <?php // DECADES LISTING AT TOP OF PAGE // Fetch the records of the DECADE $row while($linkrow = mysql_fetch_array($links)) { // Show links to DECADE queries and add "0's" to the result echo '<a href="seasonslistdecades.php?searchstring='; echo $linkrow['letter']. '">'.$linkrow['letter'].'0\'s</a> '; } ?> </p> <hr /> <?php // TOP PAGINATION // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page$rpp\">$page</a> "; } } // creating previous and next link // plus the link to go straight to // the first and last page if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page$rpp\"><a href=\"$self?page=$page$rpp\"><img src=\"../../images/icons/Prev.png\" height=\"20\" alt=\"Previous\" title=\"Previous Page\" /></a> "; $first = " <a href=\"$self?page=1$rpp\"><img src=\"../../images/icons/First.png\" height=\"20\" alt=\"First\" title=\"First Page\" /></a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page$rpp\"><img src=\"../../images/icons/Next.png\" height=\"20\" alt=\"Next\" title=\"Next Page\" /></a> "; $last = " <a href=\"$self?page=$maxPage$rpp\"><img src=\"../../images/icons/Last.png\" height=\"20\" alt=\"Last\" title=\"Last Page\" /></a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo $first . $prev . $nav . $next . $last;?> // LIMIT ROWS DROPDOWN <div class="drop_right" ><form action="" method="post" name="records_per_page" target="_self"> Number of Records per page <select name="records_per_page" id="records_per_page"> <?php $values = array(5,10,15,20,25,30,40,50); $options = ''; foreach($values as $value){ $select = ($rowsPerPage == $value) ? ' selected="selected"':''; $options .= "<option value='$value'$select>$value</option>\n"; } echo $options; ?> </select> <input type="submit" name="SUB" id="SUB" value="Submit" /> </form></div> <p> <?php // SEASONS LISTING // Show the Table Headers echo ' <table align="center" cellspacing="0" cellpadding="0"> <tr> <th>ID</th> <th>Name</th> <th>From</th> <th>To</th> <th>Edit</th> </tr> '; // Show the Season Data while($row = mysql_fetch_array($result)) { echo ' <tr> <td>'.$row['season_id'] .'</td> <td>'.$row['season_name'] .'</td> <td>'.$row['startdate'] .'</td> <td>'.$row['enddate'] .'</td> <td><img src="../../images/icons/Search.png" height="20" alt="View" /> <img src="../../images/icons/Edit.png" height="20" alt="Edit" /> <img src="../../images/icons/Close.png" height="20" alt="Delete" /></td> </tr> ' ; } echo '</table> '; // BOTTOM PAGINATION // print the navigation link echo $first . $prev . $nav . $next . $last; ?> <br /> <p> </p> <!-- end .content --></div> <div class="footer"> <p>This .footer contains the declaration position:relative; to give Internet Explorer 6 hasLayout for the .footer and cause it to clear correctly. If you're not required to support IE6, you may remove it.</p> <!-- end .footer --></div> <!-- end .container --></div> </body> </html>
-
Wouldn't the correct logic be to pass the $rowsPerPage value as a get parameter in the URLs and if it is set to a value greater than zero to override the default $rowsPerPage = 25; line of code? Since your calculations then use the $rowsPerPage value to determine the correct LIMIT clause in the query, getting the $rowsPerPage variable to have the correct value at the start of the calculations should make the code work.
-
You can actually increment strings in php and it will work, except when you increment 'ZZZ', it becomes 'AAAA' and you would need to account for that 'roll over' value in your logic.