-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
problem in displaying progress bar with percentage while uploading.
kicken replied to sanjay_zed's topic in PHP Coding Help
Note that to use the above feature you have to be using php 5.4 with both session.auto_start and session.upload_progress.enabled turned on in your php.ini. -
You should write something describing your problem rather than just post code. if(mysql_num_rows($query) == 1) { $compny = mysql_query("SELECT * FROM company WHERE value='". $comp ."'"); $company = mysql_result($compny, 0); if(mysql_num_rows($company) == 0) { echo "Company not found"; die(); } $getcompstt = mysql_query("SELECT stat FROM company WHERE value='". $comp ."' LIMIT 1"); $getcompstat = mysql_result($getcompstt, 0); elseif($getcompstat == "3") You have an elseif there at the end that is not attached to any preceding if statement.
-
Normally when the browsers submit the filename, the include only the base name an no directory components. A malicious user could however alter the request to include a full path to a file as the filename. For example changing the header from Content-disposition: form-data; name="upload"; filename="somefile.jpg" to Content-disposition: form-data; name="upload"; filename="/etc/passwd" If your not careful you might end up enabling other means for the user to manipulate the filename as well.
-
If I'm understanding what you want (sounds like what TortoiseMerge has) it could probably be done fairly simply for desktop browsers at least. Not sure about mobile compatibility though. Basically you'd just create a div that is position:fixed on the side of the window, set to 100% height. Have an image or a styled div inside there as your marker/indicator. As the user scrolls through the page have a small bit of JS calculate the position and move the marker accordingly.
-
Populating a table with gaps in the SQL results
kicken replied to idontkno's topic in PHP Coding Help
I just wrote the code off the top of my head, didn't test it at all. Bound to be typos which is all that was. -
Querying and displaying data using php and mysql using checkboxes?
kicken replied to masterk123's topic in PHP Coding Help
You have to construct a query with the appropriate where clause conditions based on the checkboxes that are selected. Something like: $sql = 'SELECT * FROM test '; $where=array(); if (isset($_POST['option'])){ foreach ($_POST['option'] as $opt){ switch ($opt){ case 'Wifi': $where[] = "Wifi='yes'"; break; case 'Bluetooth': $where[] = "Bluetooth='yes'"; break; case 'GPS': $where[] = "GPS='yes'"; break; } } } if (count($where)>0){ $sql .= 'WHERE '.implode(' AND ', $where); } //query and display the results. -
You can't validate the page with the PHP code in it still. You have to run the output of the php through the validator. When the validator hits your page, it will not have a valid session. As such it is going to see the output for your session expired notice, which ends up generating a page consisting of: <h1>Session Expire Now.......Please Login First</h1> <p> <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a> </p> </body> </html> Notice you have no header, no doctype, no body opening tag, etc. All this is missing because it is contained inside your if statement and only gets output if there is a valid session.
-
Populating a table with gaps in the SQL results
kicken replied to idontkno's topic in PHP Coding Help
Just because there may not be some magic built in function to do what you want does not mean PHP is incapable of doing it. You can store the data into an array of any dimension size you want as you fetch it from the database. If necessary, you can sort it using one of the many sorting functions, usort can handle pretty much any type of sort you want. This is just an example of how one might produce the table you want, while using a more proper database layout. Depending on your requirements you might even break it down further to having one row per result rather than using result1, result2, and result3 columns. <?php $sql = 'SELECT labName, result1, result2, result3, period FROM labResults ORDER BY labName, period'; $res = mysql_query($sql); $labResults = array(); while ($row=mysql_fetch_assoc($res)){ $lab = $row['labName']; $period = $row['period']; $labResults[$lab][$period] = array( 1=> $row['result1'], 2=> $row['result2'], 3=> $row['result3'] ); } ?> <table> <thead> <tr> <th>Period 1</th> <th>Period 2</th> <th>Period 3</th> <th>Period 4</th> </tr> </thead> <tbody> <?php foreach ($labResults as $labName=>$periods): ?> <tr> <th><?php echo $labName; ?></th> <?php //Use a for loop so we account for all four periods, even if one is missing in a particular lab result set for ($period=1; $period <= 4; $period++){ echo '<td>'; if (isset($periods[$period])){ foreach ($ as $resNum=>$resData){ echo 'Result Set '.$resNum.': '.$resData; } } else { echo ' '; } echo '</td>'; } ?> </tr> <?php endforeach; ?> </tbody> </table> -
I'm not familar with jquery too much, but my understanding from reading the docs is that you'd need your server-side script to look for the $_GET['callback'] parameter and then output that as a function to call with the json as an argument. Eg. <?php header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('content-type: application/json; charset=utf-8'); $json = ''; try { $dbh = new PDO("mysql:host=localhost;dbname=$db_name", $db_user, $db_pass); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $dbh->prepare($sql); // $stmt->bindParam("id", $_GET[id]); $stmt->execute(); $stores = $stmt->fetchAll(PDO::FETCH_OBJ); $dbh = null; $json = '{"items":' . json_encode($stores) . '}'; } catch (PDOException $e) { $json = '{"error":{"text":' . $e->getMessage() . '}}'; } echo $_GET['callback'].'('.$json.');';
-
<?= is shorthand for <?php echo, so that statement is essentially: <?php echo $name; ?> The shorthand only works if short tags are enabled though (prior to 5.4 at least)
-
Get the domain name of a website which includes my includes file
kicken replied to o3xa's topic in PHP Coding Help
Pass the domain as a parameter in the URL. include('http://o3xa-seo.info/bata-links.php?amount=10&domain='.urlencode($_SERVER['HTTP_HOST'])); -
A description typically has spaces and punctuation, possibly numbers. ctype_alpha will return false if any of those are present. The check is probably unnecessary, could just remove it.
-
Create a function that contains the logic for the sorting, then use uksort with that function to perform the sort. Your function should accept two arguments, $item1 and $item2 and return a value as follows: [*] Return a value less than zero if $item1 sorts before $item2 [*] Return zero if $item1 is the same as $item2 [*] Return a value greater than zero if $item2 sorts before $item1 Then just use a normal foreach loop to output the array after it's sorted.
-
Get the domain name of a website which includes my includes file
kicken replied to o3xa's topic in PHP Coding Help
How are you including this file? If you include it via a file path, eg: include('/path/to/include.php'); Then the domain should just be in $_SERVER['HTTP_HOST']. If your including it as a URL though, say include('http://www.yoursite.com/include.php'); Then you have to pass the domain as a parameter in the query string in order to get it in the include. -
Populating a table with gaps in the SQL results
kicken replied to idontkno's topic in PHP Coding Help
I would put your data into an array structure which represents your table and just leave the empty columns blank in the array. Then you can make a simple loop to show the array as a table. -
It shifts because a table cell tries to use only the minimum space necessary. With a smaller image it is using less space. That extra space gets allocated to the other cell instead. If you want to cells to be a consistent size then you have to set their width using either CSS or the width attribute. You are also missing your <tr></tr> tags around your cells. <table> <tr> <td class="faceCompareCell"> <img src="design/facerejuv1.jpg" alt="Massage"> </td> <td> Did you know that 10,000 baby boomers are retiring every day in the US? <br> <br> If "GROOVY" and (image of a piece symbol) meant something to you in the 60's than BHRT, BOTOX®, LASERS, WEIGHT MANAGEMENT AND WELLNESS should mean something to you <b>NOW</b>. <ul> <li>Optimize your hormones</li> <li>Look much younger</li> <li>Feel healthy and terrific</li> <li>Possess awesome energy</li> </ul> </td> </tr> </table> Then add to your css .faceCompareCell{ width: 50%; }
-
This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=358122.0
-
In this specific case, it won't contain multiple columns. The API is a generic solution though which is designed to handle the case of multiple columns. Even if the query only returns one column the code is still going to generate an array with a key for the column, and when you access it you will have to specify the key.
-
To provide a few more specific answers (though I agree with thorpe in that enabling SSL for all is good): Yes, you should at minimum use SSL when posting the login information to ensure it is encrypted. Setting the action to an https url is technically enough, as that will cause the post itself to be encrypted. You should serve the login page itself over https as well though so that the browser includes a visual indication that the page is encrypted. That helps users feel safer if they can see the SSL signs before entering their details. Encrypting the login page itself can help prevent man-in-the-middle attacks as well.
-
Yes, because the array could contain multiple columns if you were to select multiple columns. As such you have to specify which one you want to access within the array by using the key name.
-
Remove all your @-sign prefixes so you can see any errors that are being generated. You should almost never use @ in your code like that. Make sure you have error reporting enabled as well. At the top of the script put: error_reporting(-1); ini_set('display_errors', 'On');
-
Your first call to mysqli_fetch_assoc there is returning the first row, but you just drop it and never echo that row out. So if your seeing 5 results echoed, that means your getting 6 returned, but your ignoring the first one.
-
Not sure if a find and replace would work. I use the PDO api in my application rather than the function based api. You could create an include file of wrapper functions to re-define the mssql_* functions, I did something like that in my code as a quick-fix to get some third-party code working until it could be re-written. For example: if (!function_exists('mssql_query')){ include 'mssql_compat.inc.php'; } mssql_compat.inc.php - keep in mind this is using pdo as a base, your implementations would differ. <?php /** * mssql_query replacement. * * Provides a wrapper for mssql_query * * @param string $sql The query to execute. * @param PDO $link The connection to query on. Defaults to the currently active connection. * @return PDOStatement */ function mssql_query($sql, $link=null){ if (!$link) $link=DB::GetFromPool(); $stmt = $link->prepare($sql); if (!$stmt){ throw new SQLException($link, $sql); } if (!$stmt->execute()){ throw new DatabaseException($link, $stmt, $sql); } $stmt->_rows = $stmt->fetchAll(); reset($stmt->_rows); return $stmt; } /** * mssql_fetch_array replacement. * * Provides a wrapper for mssql_fetch_array * * @param PDOStatement $stmt The result set. * @param int $type The type of results to fetch, should be one of the PDO class constants. * @return mixed */ function mssql_fetch_array($stmt, $type=PDO::FETCH_BOTH){ if (!($stmt instanceof PDOStatement)){ throw new InvalidArgumentException('$stmt must be a PDOStatement object'); } if (is_array($stmt->_rows)){ $row=current($stmt->_rows); next($stmt->_rows); if ($type == PDO::FETCH_BOTH || !is_array($row)){ return $row; } else { $ret=array(); foreach ($row as $k=>$v){ if ($type == PDO::FETCH_ASSOC && !is_int($k)){ $ret[$k] = $v; } else if ($type == PDO::FETCH_NUM && is_int($k)){ $ret[$k] = $v; } } return $ret; } } else { return false; } } ///more functions
-
The mssql_* set of functions are not supported since 5.3. The preferred extensions to use now are SQLSRV (on windows) and ODBC (on linux). If your code uses the mssql_* functions you will either have to re-write the code to use the new drivers, downgrade back to php 5.2, or scour the web and see if you can find a third-party dll to enable the extension.