PHP - Accessibility For Each File Depending On Position Declared
Hello All,
I have designed a small php module Which has more than 80 .php files. I want to give the access level for all those files through a global access.php file. But i am not getting how it can be developed. I made a table in database which has all the scripts name. When those are checked value 1 it has to be visible for those users who come under a perticular position like MD, CEO, Sales Manager etc. Here is my table structure
script.JPG 20.61KB
0 downloads
and i tried doing like this
if($_SESSION['pos']=='admin') { echo "<h1> SORRY YOU DONT HAVE ACCESS </h1>"; } else { // file contents... } Similar TutorialsHey im having troube making this code as i have no idea how to do it... basically what im trying to do is for example if the index.php?id=XXX i want to echo "this" and if it is just index.php i want to echo "that" your help would be nice thanks <?php $id_lang = $_GET['id']; if($id_lang == $id_lang){ $result = mysql_query("SELECT * FROM pages WHERE id='$id_lang' ",$connect); while($row44 = mysql_fetch_assoc($result)) { $js_langdir = $row44['lang_dir']; }} else{ $js_langdir = "LTR"; } ?> Gooday Coders. Im using php 5.4 with xampp 1.8. Each time I run this script "add+stock.php", the script jumps to line 240 saying header is already defined. Thus referring to the session headers. What can I do to get rid of these header errors?
add_stock.php
<?php include_once("init.php"); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>NIC - Add Stock Category</title> <!-- Stylesheets --> <link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet'> <link rel="stylesheet" href="css/style.css"> <link rel="stylesheet" href="js/date_pic/date_input.css"> <link rel="stylesheet" href="lib/auto/css/jquery.autocomplete.css"> <!-- Optimize for mobile devices --> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <!-- jQuery & JS files --> <?php include_once("tpl/common_js.php"); ?> <script src="js/script.js"></script> <script src="js/date_pic/jquery.date_input.js"></script> <script src="lib/auto/js/jquery.autocomplete.js "></script> <script> /*$.validator.setDefaults({ submitHandler: function() { alert("submitted!"); } });*/ $(document).ready(function() { $("#supplier").autocomplete("supplier1.php", { width: 160, autoFill: true, selectFirst: true }); $("#category").autocomplete("category.php", { width: 160, autoFill: true, selectFirst: true }); // validate signup form on keyup and submit $("#form1").validate({ rules: { name: { required: true, minlength: 3, maxlength: 200 }, stockid: { required: true, minlength: 3, maxlength: 200 }, cost: { required: true, }, sell: { required: true, } }, messages: { name: { required: "Please Enter Stock Name", minlength: "Category Name must consist of at least 3 characters" }, stockid: { required: "Please Enter Stock ID", minlength: "Category Name must consist of at least 3 characters" }, sell: { required: "Please Enter Selling Price", minlength: "Category Name must consist of at least 3 characters" }, cost: { required: "Please Enter Cost Price", minlength: "Category Name must consist of at least 3 characters" } } }); }); function numbersonly(e){ var unicode=e.charCode? e.charCode : e.keyCode if (unicode!=8 && unicode!=46 && unicode!=37 && unicode!=38 && unicode!=39 && unicode!=40 && unicode!=9){ //if the key isn't the backspace key (which we should allow) if (unicode<48||unicode>57) return false } } </script> </script> </head> <body> <!-- TOP BAR --> <?php include_once("tpl/top_bar.php"); ?> <!-- end top-bar --> <!-- HEADER --> <div id="header-with-tabs"> <div class="page-full-width cf"> <ul id="tabs" class="fl"> <li><a href="dashboard.php" class="dashboard-tab">Dashboard</a></li> <li><a href="view_sales.php" class="sales-tab">Sales</a></li> <li><a href="view_customers.php" class=" customers-tab">Customers</a></li> <li><a href="view_purchase.php" class="purchase-tab">Purchase</a></li> <li><a href="view_supplier.php" class=" supplier-tab">Supplier</a></li> <li><a href="view_product.php" class="active-tab stock-tab">Stocks / Products</a></li> <li><a href="view_payments.php" class="payment-tab">Payments / Outstandings</a></li> <li><a href="view_report.php" class="report-tab">Reports</a></li> </ul> <!-- end tabs --> <!-- Change this image to your own company's logo --> <!-- The logo will automatically be resized to 30px height. --> <a href="#" id="company-branding-small" class="fr"><img src="<?php if(isset($_SESSION['logo'])) { echo "upload/".$_SESSION['logo'];}else{ echo "upload/NIC.png"; } ?>" alt="Point of Sale" /></a> </div> <!-- end full-width --> </div> <!-- end header --> <!-- MAIN CONTENT --> <div id="content"> <div class="page-full-width cf"> <div class="side-menu fl"> <h3>Stock Management</h3> <ul> <li><a href="add_stock.php">Add Stock/Product</a></li> <li><a href="view_product.php">View Stock/Product</a></li> <li><a href="add_category.php">Add Stock Category</a></li> <li><a href="view_category.php">view Stock Category</a></li> <li><a href="view_stock_availability.php">view Stock Available</a></li> </ul> </div> <!-- end side-menu --> <div class="side-content fr"> <div class="content-module"> <div class="content-module-heading cf"> <h3 class="fl">Add Stock </h3> <span class="fr expand-collapse-text">Click to collapse</span> <div style="margin-top: 15px;margin-left: 150px"></div> <span class="fr expand-collapse-text initial-expand">Click to expand</span> </div> <!-- end content-module-heading --> <div class="content-module-main cf"> <?php //Gump is libarary for Validatoin if(isset($_POST['name'])){ $_POST = $gump->sanitize($_POST); $gump->validation_rules(array( 'name' => 'required|max_len,100|min_len,3', 'stockid' => 'required|max_len,200', 'sell' => 'required|max_len,200', 'cost' => 'required|max_len,200', 'supplier' => 'max_len,200', 'category' => 'max_len,200' )); $gump->filter_rules(array( 'name' => 'trim|sanitize_string|mysql_escape', 'stockid' => 'trim|sanitize_string|mysql_escape', 'sell' => 'trim|sanitize_string|mysql_escape', 'cost' => 'trim|sanitize_string|mysql_escape', 'category' => 'trim|sanitize_string|mysql_escape', 'supplier' => 'trim|sanitize_string|mysql_escape' )); $validated_data = $gump->run($_POST); $name = ""; $stockid = ""; $sell = ""; $cost = ""; $supplier = ""; $category = ""; if($validated_data === false) { echo $gump->get_readable_errors(true); } else { $name=mysql_real_escape_string($_POST['name']); $stockid=mysql_real_escape_string($_POST['stockid']); $sell=mysql_real_escape_string($_POST['sell']); $cost=mysql_real_escape_string($_POST['cost']); $supplier=mysql_real_escape_string($_POST['supplier']); $category=mysql_real_escape_string($_POST['category']); $count = $db->countOf("stock_details", "stock_name ='$name'"); if($count>1) { $data='Dublicat Entry. Please Verify'; $msg='<p style=color:red;font-family:gfont-family:Georgia, Times New Roman, Times, serif>'.$data.'</p>';// ?> <script src="dist/js/jquery.ui.draggable.js"></script> <script src="dist/js/jquery.alerts.js"></script> <script src="dist/js/jquery.js"></script> <link rel="stylesheet" href="dist/js/jquery.alerts.css" > <script type="text/javascript"> jAlert('<?php echo $msg; ?>', 'NIC'); </script> <?php } else { if($db->query("insert into stock_details(stock_id,stock_name,stock_quatity,supplier_id,company_price,selling_price,category) values('$stockid','$name',0,'$supplier',$cost,$sell,'$category')")) { $db->query("insert into stock_avail(name,quantity) values('$name',0)"); $msg=" $name Stock Details Added" ; header("Location: add_stock.php?msg=$msg"); }else echo "<br><font color=red size=+1 >Problem in Adding !</font>" ; } } } if(isset($_GET['msg'])){ $data=$_GET['msg']; $msg='<p style=color:#153450;font-family:gfont-family:Georgia, Times New Roman, Times, serif>'.$data.'</p>';// ?> <script src="dist/js/jquery.ui.draggable.js"></script> <script src="dist/js/jquery.alerts.js"></script> <script src="dist/js/jquery.js"></script> <link rel="stylesheet" href="dist/js/jquery.alerts.css" > <script type="text/javascript"> jAlert('<?php echo $msg; ?>', 'NIC'); </script> <?php } ?> <form name="form1" method="post" id="form1" action=""> <table class="form" border="0" cellspacing="0" cellpadding="0"> <tr> <?php $max = $db->maxOfAll("id", "stock_details"); $max=$max+1; $autoid="SD".$max.""; ?> <td><span class="man">*</span>Stock ID:</td> <td><input name="stockid" type="text" id="stockid" readonly maxlength="200" class="round default-width-input" value="<?php echo $autoid; ?>" /></td> <td><span class="man">*</span>Name:</td> <td><input name="name"placeholder="ENTER CATEGORY NAME" type="text" id="name" maxlength="200" class="round default-width-input" value="<?php echo $name; ?>" /></td> </tr> <tr> <td><span class="man">*</span>Cost:</td> <td><input name="cost" placeholder="ENTER COST PRICE" type="text" id="cost" maxlength="200" class="round default-width-input" onkeypress="return numbersonly(event)" value="<?php echo $cost; ?>" /></td> <td><span class="man">*</span>Sell:</td> <td><input name="sell" placeholder="ENTER SELLING PRICE" type="text" id="sell" maxlength="200" class="round default-width-input" onkeypress="return numbersonly(event)" value="<?php echo $sell; ?>" /></td> </tr> <tr> <td>Supplier:</td> <td><input name="supplier" placeholder="ENTER SUPPLIER NAME" type="text" id="supplier" maxlength="200" class="round default-width-input" value="<?php echo $supplier; ?>" /></td> <td>Category:</td> <td><input name="category" placeholder="ENTER CATEGORY NAME" type="text" id="category" maxlength="200" class="round default-width-input" value="<?php echo $category; ?>" /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> <input class="button round blue image-right ic-add text-upper" type="submit" name="Submit" value="Add"> (Control + S) <td align="right"><input class="button round red text-upper" type="reset" name="Reset" value="Reset"> </td> </tr> </table> </form> </div> <!-- end content-module-main --> </div> <!-- end content-module --> </div> <!-- end full-width --> </div> <!-- end content --> <!-- FOOTER --> <div id="footer"> <p>Any Queries email to <a href="mailto:sridhar.NIC@gmail.com?subject=Stock%20Management%20System">sridhar.NIC@gmail.com</a>.</p> </div> <!-- end footer --> </body> </html> Hi, Basically I am going to give a short description to my problem with pseduo and comments (-->), there is too much to paste all my code he basically include(config.php) --> database connection include(global.php) --> class is instantiated here as $p ($p is GLOBAL) --> I print_r the $p value here, and it shows (debugging) switch() case x: include file.php; break; --> but when I try to access it or print_r it here (here being within the file.php), via the file that has been included above "include file.php", it does not see it. I have to re-declare the $p variable with the class, within the included file. any tips as how to solve this please; I dont see why it wouldnt see it, since all the file is that I am including is an HTML file with a few PHP lines, which checks if a user has permission: if(!$p->check()) redirect("index.php"); I don't understand why "if(isSet($_GET['sid'])) " works before it is declared in the variable name(" $name = $_GET['sid'];"). 1. How does php store the date in this get statement? 2. Is GET an array? Code: [Select] if(isSet($_GET['sid'])) { echo "<h2>Exercise</h2>"; $name = $_GET['sid']; $timein = time(); $quest=1; $nextquest=2; } else { echo "<h2>Enter Student Number:</h2>"; $quest=0; $nextquest=0; } I'm receiving a cannot redeclare function error. I have a functions.php pack that I only require_once once. require_once 'functions.php'; require_once 'classes.php'; A little further into the code I conditionally require another php file. require_once 'dataentry.php'; It appears that when the require_once 'dataentry.php' line is hit, I receive this redeclare error. I do not call any include or require in dataentry.php. The first function in my function pack throws this error, and when I comment it out, the next function throws the error. Im appalled as to the reasoning for this error. Any Thoughts? Dear all, I am new to the forums, with a hope that somebody can point me in the right direction. I am coding a new photo website, and am doing it with PHP to maximize my flexibility. In essence I want to have a set of gallery folder on the server, and the site reads off these folders and automatically generates the required galleries. My PHP code is below, along with a detail of the exact problem: <?php $main = "Collections/"; # Location of galleries $big = "Large/"; # Location of big versions (subdir within each gallery) $i = 0; #Gallery Iterator #Searching for galleries & Checking only for directories (save them im $galleries array) $tempgalleries = scandir($main); foreach ($tempgalleries as $gallery_iterate) { if (!is_dir($gallery_iterate)) { $galleries[]=$gallery_iterate; } } #Iterating galleries. Collecting each gallery's images (saving in $GalleryImages.$i). This creates an image array for each $galleries[$i] for($i=0; $i<=sizeof($galleries)-1; $i++) { #Making the title nice (from the the directory names) $GalleryTitles[$i] = str_replace('_',' ', $galleries[$i]);; $temp_gallery = opendir($main.$galleries[$i]); #Checking for Images and storing in array if valid while (false !== ($image = readdir($temp_gallery))) { if ($image != "." && $image != ".." && $image != rtrim($big,"/") && strstr($image,'.jpg')) { ${$GalleryImages_.$i}[] = $image; } } #Sorting the images numerically natsort(${$GalleryImages_.$i}); closedir($temp_gallery); } #Better location for the buttons!! #Printing the galleries and all the html required for naming, separation, etc.. This is also an iteration for($i=0; $i<=sizeof($galleries)-1; $i++) { echo('<div class="galleries_hidden" id="gallery_'.$i.'"><hr><br><div class="Gallery_Title"><b><i><big>'.$GalleryTitles[$i].'</big></i></b></div><br>'); $folder=$galleries[$i]; foreach(${$GalleryImages_.$i} as $thumb_image) { echo '<a href="'.$main . $folder .'/'. $big . 'large_'. $thumb_image . '" rel="lightbox['.$folder.']" title="'.$folder.'"><img src="' . $main . $folder .'/'. $thumb_image. '" alt="'.$folder.'" class="Gallery_Image" /></a>'; } echo('</div>'); } #Making the buttons to cycle the galleries for($i=0; $i<sizeof($galleries); $i++) { echo('<input type="button" id="gallery_'.$i.'" value="Show '.$GalleryTitles[$i].'" onclick="showgallery(');echo("'gallery_".$i."');");echo('" /><br><br>'); } ?> I have managed to make each aspect work, exept one. The last portion, as commented: #Making the buttons to cycle the galleries for($i=0; $i<sizeof($galleries); $i++) { echo('<input type="button" id="gallery_'.$i.'" value="Show '.$GalleryTitles[$i].'" onclick="showgallery(');echo("'gallery_".$i."');");echo('" /><br><br>'); } This piece of code generates buttons which shows one gallery, and hides the rest. This is done by changing the classes of the divs from "galleries_visible" to "galleries_hidden", as applicable. This is done using a javascript declared in the header as follows: Code: [Select] <script type="text/javascript"> function showgallery(id) { var divall = document.getElementsByTagName("div"); var i=0; for (i=0;i<divall.length;i++) { if(divall[i].className == "galleries_visible") { divall[i].className = "galleries_hidden"; } var showdiv = document.getElementById(id); showdiv.className = "galleries_visible"; return false; } </script> When I have the button-generating php code below the gallery-generating php code, then the javascript seems to work, by showing and hiding respective galleries. These galleries and their litebox viewer all work normally. However, when putting the button-creator php above the gallery-generator php, then the buttons appear as normal, and the javascript runs, but it cannot find the div with the id it searches for: Code: [Select] var showdiv = document.getElementById(id); showdiv.className = "galleries_visible"; I am confused. The PHP code makes several arrays which stores all the file and folder information, and these arrays are read by the button-generator irrespective of its position (I know this because the buttons are generated based on the content of non-empty arrays). Why can't the javascript change the gallery-containing divs when they are below the button-containing div? Any help is greatly appreciated, I just cant seem to find whats wrong! Kind regards, Frederik Hi all, I have this structure of two functions: function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } function normaliza($text){ function entre($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } foreach (count_chars($text, 1) as $i => $val) { if(chr($i)=='<'){ $totaltag = $val; } } for($u=0; $u <= $totaltag; $u++){ $parsed = entre($text, "<", ">"); $text = str_replace('<'.$parsed.'>',"",$text); } return $text; } The I passed a text named $data throught both functions and I got the correct return: $status = get_string_between($data, 'Inativo', 'CNPJ'); $status = normaliza($status); echo $status.' '; Just after, I passed the same folowing text throught the same both functions: $cnpj = get_string_between($data, 'CNPJ', 'Grau'); $cnpj = normaliza($status); echo $cnpj.' '; And I got this error: Cannot redeclare entre() (previously declared in C:\Users\entidade.php:47) in C:\Users\entidade.php on line 47 Why? I thougth this kind strange because it didin't gave the same error for the function get_string_between. Thanks danilo jr. Newb here trying to build a form that works with ints to count how many red shirts die in a classic episode of star trek (exercise to get better with forms and ints). I have an error which reads as '7 Error message: Undefined index: rsTot'. I have tried a few things and read that setting it(casting it?) as a float was the safest way to work with the int, however each thing i've attempted results in some sort of error so after a day of reading and trying i'm very confused and hoping for an answer I can understand here.
I have read through stackOverflow for an answer but not seen one which i can understand and apply that speaks to the problem i'm having of initially entering and process a number as an int which i can later do some math on.
error can be seen he http://zephir.seattlecentral.edu/~jstein11/itc250/z14/w03c0102_OOPform/w03c0102_OOPform.php
<?php //w03c0102_OOPform require '../inc_0700/config_inc.php'; #provides configuration, pathing, error handling, db credentials //END CONFIG AREA ---------------------------------------------------------- $rsTot = (float)$_POST['rsTot'];// float more forgiving int $rsSurvived = (float)$_POST['rsSurvived']; $rsSum = $rsTot - $rsSurvived; $rsRatio = 0; # Read the value of 'action' whether it is passed via $_POST or $_GET with $_REQUEST if(isset($_REQUEST['act'])){$myAction = (trim($_REQUEST['act']));}else{$myAction = "";} switch ($myAction) {//check 'act' for type of process case "display": # 2)Display user's name! showName(); break; default: # 1)Ask user to enter their name showForm(); } function showForm() {# shows form so user can enter their name. Initial scenario get_header(); #defaults to header_inc.php ?> <script type="text/javascript" src="<?=VIRTUAL_PATH;?>include/util.js"></script> <script type="text/javascript"> function checkForm(thisForm) {//check form data for valid info if(empty(thisForm.YourName,"Field Empty, please fill out")){return false;} return true;//if all is passed, submit! } </script> <p align="center"><?=smartTitle();?></p> <h3 align="center">Star Trek Classic</h3> <h2 align="center">Death-Shirt Calculator</h2> <form action="<?=THIS_PAGE;?>" method="post" onsubmit="return checkForm(this);"> <p align="center">Classic Star Trek Episode Name<br /> <input type="text" name="epName" /><br /><br /> Esitmated number of officers with red shirts<br /> <input type="text" name="rsTot" /><br /><br /> Esitmated number of officers with red shirts<br /> to actually survive the episode<br /> <input type="int" name="rsSurvived" /><br /><br /> <input type="submit" value="Go!"> </p> <input type="hidden" name="act" value="display" /> </form> <?php get_footer(); #defaults to footer_inc.php } function showName() {#form submits here we show entered name get_header(); #defaults to footer_inc.php if(!isset($_POST['epName']) || $_POST['epName'] == '') {//data must be sent feedback("No form data submitted"); #will feedback to submitting page via session variable myRedirect(THIS_PAGE); } if(!ctype_alnum($_POST['epName'])) {//data must be alphanumeric only feedback("Only letters and numbers are allowed. Please re-enter your name."); #will feedback to submitting page via session variable myRedirect(THIS_PAGE); } $epSubmitted = strip_tags($_POST['epName']);# strip data entered echo '<h3 align="center">' . smartTitle() . '</h3>'; echo '<p align="center">Episode Name: <b>' . $epSubmitted . '</b><br />'; echo '<p align="center">Total Red Shirts Appearing: <b>' . $rsTot . '<br />'; echo 'Red Shirts Still Breathing at End of Episode: <b>' . $rsSurvived . '<br />'; echo 'Red Shirt Episode Survival Ratio: <b>' . $rsRatio . '</b>!</p>'; echo '<p align="center"><a href="' . THIS_PAGE . '">RESET</a></p>'; get_footer(); #defaults to footer_inc.php } ?> Edited by Chezshire, 25 May 2014 - 08:10 AM. Hi All, My appologies in advance. I am pretty sure that this has probably been answered before by someone...but for the life of me I carn't find the answer in any forums. My basic question is this. Can you create an object at the beginning of a script, and then call its methods from within functions? I have coded the following: <?php ///import classes to use require "booking_form_gui.php"; $booking = new booking_form_gui(); function _booking_form($form_state){ ///$booking = new booking_form_gui(); return $booking -> date_selection(); <----------this line causes the error I guess } The problem is that when I run this code, I get an error message similar to the following: Fatal error: Call to a member function date_selection() on a non-object in /var/www/drupal_6/sites/default/modules/booking_system/booking_form/booking_form.module on line 127 Anyone any ideas how I could get round this? Thanks, Mark. Fatal error: Cannot redeclare limitatexto() (previously declared in funciones.php:4) in funciones.php on line 12 <?php function limitatexto( $texto, $limite ) - Line 4 { if( strlen($texto)>$limite ) { $texto = substr( $texto,0,$limite ); } return $texto; } Line 12 Is there a way to query some information depending on if a table field DOES NOT include a specific value? I've got a table that contains over 100 locations. I want to organize the data on the frontend by country (specifically US and International). How would I go about filtering out locations that DO NOT belong in USA? $q = "SELECT * FROM table WHERE COUNTRY='USA'"; Hi all, I am trying to produce a script that will send out an email but the user can basically choose how often they get this email... I want to give them the option of daily, weekly and monthly. I have the logic down on paper and in plain English it seems to make sense but I am having a hard time converting this to code: My logic is: 1. find out how often they want to get the email (we will call this frequency, as thats what my database field is called) 2. drag out last updated timestamp (this is called last_updated and is a unix timestamp) 3. some form of compare i.e. if frequency is weekly and $today is 7 days after last reminded alert them as I say this makes sense in plain English but I'm having a hard time converting it... this is what I have come up with so far: Code: [Select] <?php // Connect include("../connect.php"); $query = "SELECT * FROM resumes_bak WHERE jobseekerid = '2610'"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { $current_timestamp = time(); echo "Current Timestamp: ".$current_timestamp; echo "<br /><br />"; $frequency = $row['frequency']; echo "Frequency is: ".$frequency; echo "<br /><br />"; $lastReminded = $row['last_reminded']; echo "Last reminded: ".$lastReminded; echo "<br /><br />"; $daily = strtotime('+1 day', $lastReminded); echo "One day forward: ".$daily; echo "<br />"; $weekly = strtotime('+1 week', $lastReminded); echo "One week forward: ".$weekly; echo "<br />"; $monthly = strtotime('+1 month', $lastReminded); echo "One month forward: ".$monthly; echo "<br /><br />"; if($frequency = 'daily' && /* I THINK I NEED ADDITIONAL CLAUSES IN HERE TO DO THE COMPARISON */ ) { echo "I am daily"; } elseif ($frequency = 'weekly') { echo "I am weekly"; } else { echo "I am monthly"; } } ?> Can anybody help me on my way here, I seem to have hit a wall! Many thanks, Greens85 i have a small search profile search and need to set $getuname variable to users username if((trim($country) !== ''&&($state) !== ''&&($city) !== '')){ $data = mysql_query("SELECT * FROM users WHERE users.state='$state' AND users.country='$Country' AND users.city='$city' ORDER BY RAND() DESC LIMIT 1 "); Echo "Country city state search"; $getuname = mysql_real_escape_string($_GET['username']); am i meant to use the get or is that only for forms? Alright, so meanwhile i wait for answer on the other thread i started another project, to fix the menu... but it was a bit confusing so now i ask you again!... Heres my current menu.php Code: [Select] <?php include "config.php"; if (!$_SESSION["valid_user"]) { echo '<a href="login.php">' . 'Login <br/><br/>' . '</a>'; } if ($_SESSION["valid_user"]) { echo '<a href="logout.php">' . 'Logout <br/><br/>' . '</a>'; echo '<a href="members.php">' . 'Control Panel <br/><br/>' . '</a>'; } echo '<a href="memberlist.php">' . 'Members <br/><br/>' . '</a>'; echo '<a href="ranking.php">' . 'Rankings <br/><br/>' . '</a>'; ?> Now it works perfectly when logged in, but when you logout the session dies, leaving me with this: Notice: Undefined index: valid_user in C:\wamp\www\kawaii\menu.php on line 5 Login Notice: Undefined index: valid_user in C:\wamp\www\kawaii\menu.php on line 10 Members Rankings Now, how can i make a login that depends on if your logged in if this happens when you logout..., i hope someone can find a solution that can work out Hi, I'm trying to display a user review system allowing user's to vote. This works fine, but I'm trying to user php to only display the rating system if the user is logged in and display alternate text if they are not. I am getting the following error: Parse error: syntax error, unexpected T_ELSE in XXXXXX on line 182 Here's the code: Code: [Select] <?php if ($_SESSION['username']){ $query = mysql_query("SELECT * FROM locations WHERE name = '$location'"); while($row = mysql_fetch_array($query)) { $rating = (int)$row[rating] ?> <div class="floatleft"> <div id="rating_<?php echo $row[id]; ?>"> <span class="star_1"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 0) { echo"class='hover'"; } ?> /></span> <span class="star_2"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 1.5) { echo"class='hover'"; } ?> /></span> <span class="star_3"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 2.5) { echo"class='hover'"; } ?> /></span> <span class="star_4"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 3.5) { echo"class='hover'"; } ?> /></span> <span class="star_5"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 4.5) { echo"class='hover'"; } ?> /></span> </div> </div> <div class="star_rating"> (Rated <strong><?php echo $rating; ?></strong> Stars) </div> <div class="clearleft"> </div> } } <?php else { echo "Log in to review"; } ?> Thanks in advance for any help. I'm sure it's something trivial but I can't see it! I have two tables categories and subcategories and what I want do is display them but here I ran into problem displaying the subcategories. Here's the code that doesn't work, all it does it displays categories. $query = "SELECT ID,name FROM `categores`"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo $row['name']; $id_main=$row['ID']; $query2 ="SELECT name_subcategory FROM subcategories WHERE id_main_category=".$row['ID']; $result2 = mysql_query($query2) or die(mysql_error()); while ($row2=mysql_fetch_array($result2)); { echo $row2['name_subcategory']; } echo "<br />"; } Display should be -category --subcategory --subcategory -another category --subcategory of "another category" . . . Hi. Im pretty sure this is easy but ive been trying for hours and looked all over the web but cant seem to do it. I have information submitted to my database which I then retrieve on another page. I retrieve the landlord name and group the same values together plus retrieve an overall rating which I average and sort by. This works and is done using: Code: [Select] $sql="SELECT landlord_name, AVG(overall) FROM $tbl_name GROUP BY landlord_name ORDER BY AVG(overall) DESC"; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ Where Im finding it difficult though is I have 5 radio buttons with values from 1-5 and want one of them to be checked if the value matches the averaged overall rating. What I've tried is: Code: [Select] if (AVG(overall)==1){ $check1="checked";} if (AVG(overall)==2){ $check2="checked";} if (AVG(overall)==3){ $check3="checked";} if (AVG(overall)==4){ $check4="checked";} if (AVG(overall)==5){ $check5="checked";} then in the form: Code: [Select] <table width="600" border="1" cellspacing="0" cellpadding="3"> <tr> <td><? echo $rows['landlord_name']; ?></td> <td><div class="avg"><form> <input type="radio" value="1" disabled="disabled" checked= "<? $check1 ?>" /> <input type="radio" value="2" disabled="disabled" checked= "<? $check2 ?>" /> <input type="radio" value="3" disabled="disabled" checked= "<? $check3 ?>" /> <input type="radio" value="4" disabled="disabled" checked= "<? $check4 ?>" /> <input type="radio" value="5" disabled="disabled" checked= "<? $check5 ?>"/> </form></div> </td> </tr> </table> To make it a bit more difficult, the AVG(overall) value will not always be an integer from 1-5 and will need to be rounded to the closest one. Think i can use ROUND for this but dont know how to put it in. Thanks for your help in advance. As you can probably tell im new to php and still learning the basics. Hello. I recently posted about getting my top nav to work which it does now (with thanks) but im having trouble getting my side navs to work. i have tried various things but i think its just a case of getting the where clause right. see what you think. any help would be great these are my files. includes/navL1.php - which does the top navigation includes/navL2.php - which does the left navigation main includes/navL3.php - which does the left navigation sub admin/layouts/admin_topnav.php admin/layouts/admin_leftnav.php admin/layouts/index.php ok so. admin topnav.php code looks like this and works Code: [Select] <?PHP require_once("../includes/initialize.php"); global $topNav; global $pageName; ?> <div id="navWrapper"> <?PHP $topNav = navL1::find_all(); ?> <div id="ddtabs3" class="solidblockmenu"> <ul> <?PHP foreach($topNav as $topNavs): ?> <li><a <?PHP echo ($pageName == $topNavs->title ? 'class="selected"' : '')?> href="<?PHP echo $topNavs->title; ?>.php" id="<?PHP echo $topNavs->title; ?>"><?PHP echo $topNavs->title; ?></a></li> <?PHP endforeach; ?> </ul> </div><!-- #ddtabs3--> </div><!-- #navWrapper--> now i need when a top nav is selected i need the correct left nav main and subs to show. this is how my left nav looks at the moment Code: [Select] <?PHP require_once("../includes/initialize.php"); global $topNav; global $pageName; ?> SOME ACCORDION SCRIPT GOES HERE <div class="arrowlistmenu"> <?PHP $nav1 = navL1::find_all(); $nav2 = navL2::find_by_nav(); $nav2 = navL2::find_by_nav(); ?> <?PHP foreach($nav2 as $nav2s): ?><h3 class="menuheader expandable"> // MAIN LEVEL <li><a <?PHP echo ($pageName == $nav2s->title ? 'class="selected"' : '')?> href="<?PHP echo $nav2s->title; ?>.php" id="<?PHP echo $nav2s->title; ?>"><?PHP echo $nav2s->title; ?></a></li></h3> <?PHP endforeach; ?> // SUB LEVEL <ul class="categoryitems"> <?PHP foreach($nav3 as $nav3s): ?> <li><a <?PHP echo ($pageName == $nav3s->title ? 'class="selected"' : '')?> href="<?PHP echo $nav3s->title; ?>.php" id="<?PHP echo $nav3s->title; ?>"><?PHP echo $nav3s->title; ?></a></li> <?PHP endforeach; ?> </ul> </div><!-- #End arrowlistmenu --> <img src="images/wrapper/loading.gif" alt="loading..." id="Pageloading" height="28" width="28" style="visibility:hidden;float:left;" /> this is the code im trying to get to work in my includes files that i can seem to get my head around includes/navL2.php Code: [Select] public static function find_by_nav(){ global $database; global $topNav; $sql = "SELECT * FROM ".self::$table_name." WHERE title="$topNav" LIMIT 1"; $result_array = self::find_by_sql($sql); return !empty($result_array) ? array_shift($result_array) : false; } the find_by_sql($sql) looks like this but i dont think you need it Code: [Select] public static function find_by_sql($sql){ global $database; $results_set = $database->query($sql); $object_array = array(); while($row = $database->fetch_array($results_set)){ $object_array[] = self::instantiate($row); } return $object_array; } im trying to use the same code to pull the sub levels inside includes/navL3.php if any of this makes sense please could you point out whats wrong thanks ricky just a little confused where ( brackets go in this statement . im just wanting to to display the information differently depending on which message is returned from the database. thanks Code: [Select] if ($info['message'])="<a href=\"freindacept.php?username=$myusername\">Has sent you a friend request </a>";{ Echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>".$info['from_user']." ".$info['message']; }elseif ($info['message'])="You have sent a contact request to"; Echo " .$info['message']<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>".$info['from_user']."; } } |