Jump to content

gnawz

Members
  • Posts

    237
  • Joined

  • Last visited

Everything posted by gnawz

  1. Guys, If anyone ever had this problem, shall I know how they solved it please? Iam not so good at Linux but know enough to set DNS and mail.
  2. Gurus, I really just need to know if the Linux box is what causes our website not to be viewable at times within our network. Like I said, it manages mail and network connections plus internal DNS. Thanks in advance.
  3. It is not the router. The router is separate. But yes, we do run internal DNS. All internet correspondence like mail has to go through the BOX first. In fact whenever there is heavy mail flow, most cases that is when we can not view our website.
  4. Dear all, I have a Redhat Linux box which manages my internal LAN and email. Sometimes, my website and some sites are not viewable from within the company but viewable outside. I sometimes have to restart the router but nothing happens. Is the Linux box affecting my network? What could be the problem?
  5. Dear all, I have php files as follows; functions.php which has all my functions including pagination functions <? /* This file contains all functions to be used in the stock system*/ ini_set('display_errors', 'On'); //Error reporting error_reporting(E_ALL); // start the session session_start(); // database connection config $dbHost = 'localhost'; $dbUser = 'root'; $dbPass = ''; $dbName = 'cstockdb'; $errorMessage; //DB functions $dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error()); mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error()); function dbQuery($sql) { $result = mysql_query($sql) or die(mysql_error()); return $result; } function dbAffectedRows() { global $dbConn; return mysql_affected_rows($dbConn); } function dbFetchArray($result) { return mysql_fetch_array($result); } function dbFetchAssoc($result) { return mysql_fetch_assoc($result); } function dbFetchRow($result) { return mysql_fetch_row($result); } function dbFreeResult($result) { return mysql_free_result($result); } function dbNumRows($result) { return mysql_num_rows($result); } function dbSelect($dbName) { return mysql_select_db($dbName); } function dbInsertId() { return mysql_insert_id(); } //End DB functions // setting up the web root and server root for // this application $thisFile = str_replace('\\', '/', __FILE__); $docRoot = $_SERVER['DOCUMENT_ROOT']; $webRoot = str_replace(array($docRoot, 'functions.php'), '', $thisFile); $srvRoot = str_replace('functions.php', '', $thisFile); define('WEB_ROOT', $webRoot); define('SRV_ROOT', $srvRoot); /* Make sure each key name in $requiredField exist in $_POST and the value is not empty */ function checkRequiredPost($requiredField) { $numRequired = count($requiredField); $keys = array_keys($_POST); $allFieldExist = true; for ($i = 0; $i < $numRequired && $allFieldExist; $i++) { if (!in_array($requiredField[$i], $keys) || $_POST[$requiredField[$i]] == '') { $allFieldExist = false; } } return $allFieldExist; } function queryString() { $qString = array(); foreach($_GET as $key => $value) { if (trim($value) != '') { $qString[] = $key. '=' . trim($value); } else { $qString[] = $key; } } $qString = implode('&', $qString); return $qString; } /* Put an error message on session */ function setError($errorMessage) { if (!isset($_SESSION['cstock_error'])) { $_SESSION['cstock_error'] = array(); } $_SESSION['cstock_error'][] = $errorMessage; } /* print the error message */ function displayError() { if (isset($_SESSION['cstock_error']) && count($_SESSION['cstock_error'])) { $numError = count($_SESSION['cstock_error']); echo '<table id="errorMessage" width="550" align="center" cellpadding="20" cellspacing="0"><tr><td>'; for ($i = 0; $i < $numError; $i++) { echo '&#8226; ' . $_SESSION['cstock_error'][$i] . "<br>\r\n"; } echo '</td></tr></table>'; // remove all error messages from session $_SESSION['cstock_error'] = array(); } } //User authentication functions function checkUser() { // if the session id is not set, redirect to login page if (!isset($_SESSION['cstockuserID'])) { header('Location: ' . WEB_ROOT . 'admin/login.php'); exit; } //The user wishes to logout if (isset($_GET['logout'])) { doLogout(); exit; } } function doLogout() { if (isset($_SESSION['cstockuserID'])) { unset($_SESSION['cstockuserID']); session_unregister('cstockuserID'); } header('Location: index.php'); exit; } function doLogin() { $userName = $_POST['txtUserName']; $password = $_POST['txtPassword']; $sql = "SELECT UserID FROM cstockusers WHERE UserName = '$userName' AND Password = PASSWORD('$password')"; $result = dbQuery($sql); if (dbNumRows($result) == 1) { $row = dbFetchAssoc($result); $_SESSION['cstockuserID'] = $row['UserID']; // log the time when the user last logged in $sql = "UPDATE cstockusers SET LastLogin = NOW() WHERE UserID = '{$row['UserID']}'"; dbQuery($sql); // now that the user is verified we move on to the next page // if the user had been in the admin pages before we move to // the last page visited if (isset($_SESSION['login_return_url'])) { $errorMessage = 'This is the page you visited last'; header('Location: ' . $_SESSION['login_return_url']); return $errorMessage; exit; } else { header('Location: index.php'); exit; } } else { $errorMessage = 'Wrong username or password. Please try again'; } return $errorMessage; } //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET['page']) && (int)$_GET['page'] > 0) { $page = (int)$_GET['page']; } else { $page = 1; } // start fetching from this row number $offset = ($page - 1) * $itemPerPage; return $sql . " LIMIT $offset, $itemPerPage"; } /* Get the links to navigate between one result page to another. */ function getPagingLink($sql, $itemPerPage = 10, $strGet = '') { $result = dbQuery($sql); $pagingLink = ''; $totalResults = dbNumRows($result); $totalPages = ceil($totalResults / $itemPerPage); // how many link pages to show $numLinks = 10; // create the paging links only if theres more than one page of results if ($totalPages > 1) { $self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ; if (isset($_GET['page']) && (int)$_GET['page'] > 0) { $pageNumber = (int)$_GET['page']; } else { $pageNumber = 1; } // print 'previous' link only if its not // on page one if ($pageNumber > 1) { $page = $pageNumber - 1; if ($page > 1) { $prev = " <a href=\"$self?page=$page&$strGet/\">[Prev]</a> "; } else { $prev = " <a href=\"$self?$strGet\">[Prev]</a> "; } $first = " <a href=\"$self?$strGet\">[First]</a> "; } else { $prev = ''; // on page one, don't show 'previous' link $first = ''; // nor 'first page' link } // print 'next' link only if its not // on the last page if ($pageNumber < $totalPages) { $page = $pageNumber + 1; $next = " <a href=\"$self?page=$page&$strGet\">[Next]</a> "; $last = " <a href=\"$self?page=$totalPages&$strGet\">[Last]</a> "; } else { $next = ''; // if on the last page, don't show 'next' link $last = ''; // nor 'last page' link } $start = $pageNumber - ($pageNumber % $numLinks) + 1; $end = $start + $numLinks - 1; $end = min($totalPages, $end); $pagingLink = array(); for($page = $start; $page <= $end; $page++) { if ($page == $pageNumber) { $pagingLink[] = " $page "; // no need to create a link to current page } else { if ($page == 1) { $pagingLink[] = " <a href=\"$self?$strGet\">$page</a> "; } else { $pagingLink[] = " <a href=\"$self?page=$page&$strGet\">$page</a> "; } } } $pagingLink = implode(' | ', $pagingLink); // return the page navigation link $pagingLink = $first . $prev . $pagingLink . $next . $last; } return $pagingLink; } ?> A folder named brand that has an index page which contains a switch and has list.php set as the default page require_once '../../functions.php'; //$_SESSION['login_return_url'] = $_SERVER['REQUEST_URI']; checkUser(); $view = (isset($_GET['view']) && $_GET['view'] != '') ? $_GET['view'] : ''; switch ($view) { case 'list' : $content = 'list.php'; $pageTitle = 'Fragrance Lounge - Brand panel'; break; case 'modify' : $content = 'modify.php'; $pageTitle = 'Fragrance Lounge - Modify Brand'; break; case 'detail' : $content = 'detail.php'; $pageTitle = 'Fragrance Lounge - Showing Brand Details'; break; case 'showbybrand' : $content = 'showbybrand.php'; $pageTitle = 'Fragrance Lounge - Showing Brands By Brand'; break; case 'showbycategory' : $content = 'showbycategory.php'; $pageTitle = 'Fragrance Lounge - Showing Brands By Category'; break; case 'showbysearch' : $content = 'showbysearch.php'; $pageTitle = 'Fragrance Lounge - Showing Brands By Searching'; break; case 'choice' : if(isset($_POST["AddBrand"]) && trim($_POST["AddBrand"])!=='') { $content = 'add.php'; $pageTitle = 'Fragrance Lounge - Add Brand'; } elseif(isset($_POST["DeleteBrand"]) && trim($_POST["DeleteBrand"])!=='') { $content = 'delete.php'; $pageTitle = 'Fragrance Lounge - Delete Brand'; } break; default : $content = 'list.php'; $pageTitle = 'Fragrance Lounge - Brand panel'; } $script = array('brand.js'); require_once '../include/template.php'; list.php The default page in the brand folder <?php if (!defined('WEB_ROOT')) { exit; } $rowsPerPage = 5; $sql = "SELECT * FROM cstockitems GROUP BY Brand"; $result = dbQuery(getPagingQuery($sql, $rowsPerPage)); $pagingLink = getPagingLink($sql, $rowsPerPage); ?> <form action="index.php?view=choice" method="post" name="frmList" id="frmList"> <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1"> <tr class="title_text"> <td width="400">Brand</td> <td width="400">Category</td> <td width="400">Date Created </td> <td width="200">View</td> <td width="200">Modify</td> </tr> <?php if (dbNumRows($result) > 0) { $i = 0; while($row = dbFetchAssoc($result)) { extract($row); if ($i%2) { $class = 'row1'; } else { $class = 'row2'; } $i += 1; ?> <tr class="<?php echo $class; ?>"> <td width="400"><?php echo $Brand; ?></td> <td width="400"><?php echo $Category; ?></td> <td width="400"><?php echo $DateAddedBrand; ?></td> <td width="200"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?view=detail&ProductID=<?php echo $ProductID; ?>">Details</a></td> <td width="200"><a href="javascript:modifyBrand(<?php echo $ProductID; ?>);">Modify</a></td> </tr> <?php } // end while ?> <tr> <td colspan="4" align="center"> <?php echo $pagingLink; ?> </td> </tr> <?php } else { ?> <tr> <td colspan="4" align="center">No brands yet</td> </tr> <tr> <td colspan="4" align="center"> </td> </tr> <?php } ?> <tr> <td colspan="4" align="right"> <input name="AddBrand" type="submit" value="Add" class="button_image"> <input type="submit" name="DeleteBrand" value="Delete" class="button_image"> </tr> </table> </form> <label class="title_text">View available brands:</label> <hr> <table width="100%" border="0"> <tr> <td><form action="index.php?view=showbybrand" method="post" name="frmByBrand"> <table width="100%" border="0"> <tr> <td width="200">By Brand:</td> <td width="200"><select name="sltBrand"> <option value="0">Select Brand</option> <? $sql = "SELECT DISTINCT Brand FROM cstockitems ORDER BY Brand ASC"; $result = dbQuery($sql); if(dbNumRows($result)) { while($row = dbFetchAssoc($result)) { echo "<option>$row[brand]</option>"; } } else { echo "<option>No Brands Present</option>"; } ?> </select></td> <td width="200"><input type="submit" name="Submit" value="Show" class="button_image" onClick="return CheckShowBrandByBrand();"> </td> </tr> </table> </form></td> </tr> <tr> <td><form name="frmByCategory" method="post" action="index.php?view=showbycategory"> <table width="100%" border="0"> <tr> <td width="200">By Category:</td> <td width="200"><select name="sltCategory"> <option value="0">Select Category</option> <? $sql = "SELECT DISTINCT Category FROM cstockitems ORDER BY Category ASC"; $result = dbQuery($sql); if(dbNumRows($result)) { while($row = dbFetchAssoc($result)) { echo "<option>$row[Category]</option>"; } } else { echo "<option>No Categories Present</option>"; } ?> </select></td> <td width="200"><input type="submit" name="Submit2" value="Show" class="button_image" onClick="return CheckShowBrandByCategory();"></td> </tr> </table> </form></td> </tr> <tr> <td><form name="frmSearchBrand" method="post" action="index.php?view=showbysearch"> <table width="100%" border="0"> <tr> <td width="200">Search:</td> <td width="200"><input type="text" name="txtSearchBrand" size="40"></td> <td width="200"><input type="submit" name="Submit3" value="Search" class="button_image" onClick="return CheckShowBrandBySearch();"></td> </tr> </table> </form></td> </tr> </table> </body> <script> function CheckShowBrandByBrand() { form = window.document.frmByBrand; if (form.sltBrand.selectedIndex == 0) { alert('You have not selected a brand to view details!'); return false; } else { return true; } } function CheckShowBrandByCategory() { form = window.document.frmByCategory; if (form.sltCategory.selectedIndex == 0) { alert('You have not selected a Category to view details!'); return false; } else { return true; } } function CheckShowBrandBySearch() { form = window.document.frmSearchBrand; if (form.txtSearchBrand.value == "") { alert('You have not entered a brand name to search!'); return false; } else { return true; } } </script> I have another file called show by category which displays database results based on a condition (By Category). It works well and shows the first set of results. The problem is that the pagination does not "paginate" my results with the condition in the SQL...(Moving to the next page) It paginates the list with the root pagination of the index.php page which diaplays list.php showbycategory.php <? require_once '../../functions.php'; $ShowBrand = $_POST["sltCategory"]; $sql = "SELECT * FROM cstockitems WHERE Category = '".$_POST["sltCategory"]."'"; $rowsPerPage = 10; $result = dbQuery(getPagingQuery($sql, $rowsPerPage)); $pagingLink = getPagingLink($sql, $rowsPerPage); ?> <form action="index.php?view=choice" method="post" name="frmList" id="frmList"> <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1"> <tr align="center" class="title_text"> <td width="400" class="">Brand</td> <td width="400" class="">Category</td> <td width="400">Date Created </td> <td width="200">View</td> <td width="200">Modify</td> </tr> <?php if (dbNumRows($result) > 0) { $i = 0; while($row = dbFetchAssoc($result)) { extract($row); if ($i%2) { $class = 'row1'; } else { $class = 'row2'; } $i += 1; ?> <tr class="<?php echo $class; ?>"> <td width="400"><?php echo $Brand; ?></td> <td width="400"><?php echo $Category; ?></td> <td width="400"><?php echo $DateAddedBrand; ?></td> <td width="200" align="center"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?view=detail&ProductID=<?php echo $ProductID; ?>">Details</a></td> <td width="200" align="center"><a href="javascript:modifyBrand(<?php echo $ProductID; ?>);">Modify</a></td> </tr> <?php } // end while ?> <tr> <td colspan="4" align="center"> <?php echo $pagingLink; ?> </td> </tr> <?php } else { ?> <tr> <td colspan="4" align="center">No brands named: <? echo '<strong>'; echo $ShowBrand; echo ' '; echo "</strong>";?></td> </tr> <tr> <td colspan="4" align="center"> </td> </tr> <?php } ?> <tr> <td colspan="4" align="right"> <input name="AddBrand" type="submit" value="Add" class="button_image"> <input type="submit" name="DeleteBrand" value="Delete" class="button_image"> <input name="btnCancel" type="button" id="btnCancel" value="Back" onClick="window.location.href='index.php';" class="button_image"> </tr> </table> </form> I have a form in list.php whose action is "index.php?view=showbycategory" The results that come should be able to paginate without losing the SQL statement condition. How do I make sure my pagination works within my SQL condition? Thanks in advance
  6. Hi, I have for long displayed information from MySQl tables in HTML form on the browser. Can someone help me on how to display MySQl table information in the following formats? Excel PDF Word Graphical ways (Pie charts, Bar graphs, Curves)
  7. gnawz

    MySQL dates

    hi Please advise on how to set MySQl to display dates in the BRITISH FORMAT ie DD/MM/YEAR noy YY/MM/DD. Thanks in advance.
  8. Hi, Any one know how to write a MySQL SQL that selects fields that are not blank based on a condition? eg a database that has many columns that are all inserted into or updated at different times; meaning at some poit some fields are updated while others remain blank. When I select, I only want to see fields that are not empty.
  9. The error is "undefined index sltBrand".
  10. I have two files; brandview.php AND brandshow.php brandview.php has a dynamic drop down form which a user selects to view results as per the selection in brandshow.php The display should come with its editing properties....eg modify and delete I however get the undefined index error and nothing is displayed. Please help me. My two files brandview.php <?php require_once '../../functions.php'; $_SESSION['login_return_url'] = $_SERVER['REQUEST_URI']; checkUser(); ?> <body> <form action="index.php?view=brandshow" method="post" name="frmShowBrand"> <table width="100%" border="0"> <tr> <td width="100">View By brand:</td> <td width="200"><select name = "sltBrand" onChange="ShowBrand();"> <option value="0">Select Brand</option> <? $sql = "SELECT DISTINCT Brand FROM cstockitems ORDER BY Brand ASC"; $result = dbQuery($sql); if(dbNumRows($result)) { while($row1 = dbFetchAssoc($result)) { echo "<option>$row1[brand]</option>"; } } else { echo "<option>No Brands Present</option>"; } ?> </select></td> </tr> </table> </form> </body> <script> function ShowBrand() { window.location.href = 'index.php?view=brandshow'; } </script> ?> brandshow.php <? require_once '../../functions.php'; //error_reporting(0); /*if (!defined('WEB_ROOT')) { exit; }*/ $ShowBrand = $_POST["sltBrand"]; $sql = "SELECT * FROM cstockitems WHERE Brand = '$ShowBrand'"; //$sql = "SELECT * FROM cstockitems GROUP BY Brand"; $rowsPerPage = 10; $result = dbQuery(getPagingQuery($sql, $rowsPerPage)); $pagingLink = getPagingLink($sql, $rowsPerPage); ?> <form action="index.php?view=choice" method="post" name="frmList" id="frmList"> <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1"> <tr align="center" class="title_text"> <td width="400" class="">Brand</td> <td width="400" class="">Category</td> <td width="400">Date Created </td> <td width="200">View</td> <td width="200">Modify</td> </tr> <?php if (dbNumRows($result) > 0) { $i = 0; while($row = dbFetchAssoc($result)) { extract($row); if ($i%2) { $class = 'row1'; } else { $class = 'row2'; } $i += 1; ?> <tr class="<?php echo $class; ?>"> <td width="400"><?php echo $Brand; ?></td> <td width="400"><?php echo $Category; ?></td> <td width="400"><?php echo $DateAddedBrand; ?></td> <td width="200" align="center"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?view=detail&ProductID=<?php echo $ProductID; ?>">Details</a></td> <td width="200" align="center"><a href="javascript:modifyBrand(<?php echo $ProductID; ?>);">Modify</a></td> </tr> <?php } // end while ?> <tr> <td colspan="4" align="center"> <?php echo $pagingLink; ?> </td> </tr> <?php } else { ?> <tr> <td colspan="4" align="center">No brands yet</td> </tr> <tr> <td colspan="4" align="center"> </td> </tr> <?php } ?> <tr> <td colspan="4" align="right"> <input name="AddBrand" type="submit" value="Add" class="button_image"> <input type="submit" name="DeleteBrand" value="Delete" class="button_image"> </tr> </table> </form>
  11. Thanks alot. It is okay now.
  12. I need to do the comparison (generate a report) from a MySQL date field whose data type is DATETIME.. Meaning it displays date and time as opposed to data type DATE which displays only the date.
  13. Iam using PHP 5.2.3 and My SQL 5.0.45 I need to select database details where the date is today. My MYSQL date type is DATETIME. I know if my MYSQL date type is DATE I do it thus; <? $sql = 'SELECT * FROM cstocksales WHERE Date = CURRENT-DATE'; ?> AND it works But how do I do it with a date data type that is DATETIME, ie return results with current data and its time when a sle was made?
  14. I know CSS, HTML and some AJAX I will take my time to learn.
  15. Thanks. I used this function... <? function checkUser() { // if the session id is not set, redirect to login page if (!isset($_SESSION['UserID'])) { header('Location: ' . WEB_ROOT . 'admin/login.php'); exit; } ?> where UserID id the user's ID in the database then I call the function at the top of every page I do not want to be seen before logging in. For the chat, I have alot of code for chat some of which is open source. What I want is to have a pop-p chat like the one of gmail of facebook. I need help on how to go about it. The same principle, I need to use as follows: I want a user to to alerted by a popup when a record hits the database, eg a record has been added or some one has logged in. Like when someone logs in to a chat then a pop-up appears to members who are logged in that someone has logged in. Any way to do that?
  16. Hi The security I need is to stop users from viewing a page when they type its link in the address bar. eg http://localhost/site/memberarea.php If this page is only viewable after logging in, one should not be able to see it even if one just types that URL. They should get a message forbidding them from viewing the file.
  17. Hi Since you are not submitting anything, The delete function is an action not event really So you should append a delete button or link against to it. If say, you have appended a link, it should invoke the delete action where ID = $Id.
  18. Hi Can someone please help me with my two problems please? I have seen lots of code about chats but none is helping me really. I need to do a chat on my website. This chat should enable individuals chat among themselves; it should however be a poup-up caht like Gmail's or facebook's. My other issue is as follows: I have a login section to my site with 3 different access levels. Each user can only see what is at their level after logging in and this works well. However, I need to restrict users from viewing what they shouldn't even if they type the URL. I mean if a user types a URL into a section where they are not authorised, It should tell them sth like "Yoou nust be logged in to view this area" Can someone help me please?
  19. Hi The messaging system and chat should be private not public An individual selects an individual to chat with. It's like a members only section
  20. Hi I have done every thing else. The site can post news, offers and new items with a small CMS to allow for CRUD functions. My problem is the messaging system and the chat. Moreover I'm expected to do a chat like gmail's of facebook's. So it the chat and private messaging system that I have a problem with. Infact, the site should allow users to create their own pages-like one page of their profile and products.
  21. Hi guys, I have to design a website with a messaging system and a chat in PHP. Please help as I have never done this. Thanks in advance.
  22. Hi I need to do the following: I have a dropdown for departments(ICT,FINANCE,SALES) Each department has different users. I want to be able to select a department then the dropdown with its list of users appears. ie I dropdown to appear depending on a user selection in another dropdown Thanks in advance
  23. PHP n MySQL is a great match (all is possible for your case)however the choice is yours! What r u comfortable at?
  24. You have to play around with the quotes.. Change " for ' and have consistency with them
  25. Hey You can use select statements to get information from the database and display it in tables or DIVs or frames using echo and print statements, as you may wish! Yes, you can use sessions in your login to check if someone is logged in before performing any action! AND YES, YOU CAN DISPLAY A PARTICULAR NO OF PAGES using php PAGINATION There are alot of tutorials on all the above Get back if stuck..
×
×
  • 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.