Jump to content

spiderwell

Members
  • Posts

    1,008
  • Joined

  • Last visited

Posts posted by spiderwell

  1. personally I wouldnt store a navigation in the database, it just generates extra database hits that dont need to be.

     

    if you look at my hlink, it passes a variable via the querystring called product and its value, in this instance shoes

     

    i have used a link with the page name of shoes.php, if you are a creating a 'one page shows all' type of script, then it would make more sense to be products.php?product=shoes, products.php?product=socks, etc etc. if you click on these links it will direct to the linked page passing the product via a querystring.

     

    the if statement can be used on its own in php, its not connected to the database/ database queries.

     

    in this example i pass the $_GET['product'] value into a variable called $product, ($_GET refers to the querystring, if it was a form it would be $_POST['product'])

     

    I then put an if statement to see if the $product value is equal to 'shoes', and if it is then show the sub menu for shoes.

     

    if I wanted it for socks too i would use the same format only to check for a value of 'socks' in the $product variable.

     

    nothing wrong with arrays, thats a great method, it will require more code to turn the array into the menu.

  2. firstly I think some code of your current navigation might give us something to work on.

    I almost always make my navigation with list items <li>somepage link</li>

     

    A simple way to do it would be to have a querystring passing a value that triggers an include for the submenu

    <?php
    $product = $_GET['product'];
    ?>
    <ul>
    <li><a href="shoes.php?product=shoes">Shoes</a></li>
    <?php
    if ($product =="shoes")
    {
    // have submenu here, a nested list would work in this instance
    }
    ?>
    <li><a href="socks.php?product=shoes">Socks</a></li>
    </ul>
    

  3. I havent tested it, but wont this work too?

     

    if ((strtoupper($_POST['state']) == 'GA') || (empty($_POST['state'])))
    {
       exit(); // Or post error to let the user know then exit
    } else {
    
    

  4. keep the trim() that cuts off white space on the inputted data at the ends of  i.e. " my name " become "my name"

     

    there is a validate email function, but it isnt built into php, you need to make a regular expression check against the input, I would say learning how to write one might be a bit hard, they aren't the easiest things in php (for me at least)

     

    here's one i prepared eariler as they say:

     

    function validateEmail($themail){
    	$result = preg_match ("/^[^@ ]+@[^@ ]+\.[^@ \.]+$/", $themail );
    	if ($result){
    		return true;
    	}else{
    
    		return false; 
    	}
    
    }
    

    stick that in the top of your php and then use it later on in your validation, its a function that returns true if email is valid, false if not

     

    if (Trim($State)=="") $validationOK=false;
    if (!validateEmail($EmailFrom)) $validationOK=false;
    
    

     

  5. heya buddy hows the assignment coming along!

     

    use some simple formating of html into your echoed php. here i have turned it into a list for you

     

    <?php
    $order = null;
    for($i=0; $i < count($_POST["Markets"]); $i++)
    {  
    $markets .= "<li>" . $_POST["Markets"][$i] . "</li>";
    }
    if(!is_null($markets))
    {    
    echo "Your Selected Markets are: <ul>  " . $markets . "</ul>";
    } 
    else
    {   
    echo "order = no selection made";
    }?>
    
    

  6. testing in different browsers shouldn't be relevant when using PHP, also I would say that you haven't really done anything wrong in your code, it all works and validates how you want it to, thats a lot bette rthan some people can manage.

     

    I don't think you need to worry about using stripslashes(), its not really needed when validating input from a form directly into an email format. it was really the partner to addslashes() which is used to escape certain characters in a string especially in conjunction with inputs into databases to stop SQL querys breaking.

     

    looking at your form I would say it works fine, but the validation is moderate to low, by that I mean you only check a few variables for having an entry and thats all. I guess it depends on the needs of your client how far you can go with this, but it is possible to validate to almost any specification, obvious ones being telephone numbers, emails, addresses all having only the right data, e.g. numbers only, text only, email is an email address .

     

    php can do redirects rather than sending a refresh header using header('Location: http://www.example.com/'), not sure if you knew that one or not.

     

    otherwise I would say well done on creating a sucessful script.

     

    [ code ]

     

    put scripts in here

     

    [ / code ]

  7. ok posting it here too, but have emailed you the scripts direct. I re wrote it so that the file will work for any user in  any user folder, which is the best way to do it really

     

    check_login.php

    <?php
    // Require the information from the includes.php page
    require_once('../config.php3');
    
    // Connect to the server and select the database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db")or die("Unable to select database");
    
    
    //
    $loginusername = false;
    $loginpassword = false;
    $err = false; // default error message is empty
    // The username and password sent from login.php
    //the isset() basically means if its there get it, otherwise dont bother
    if (isset($_POST['username'])) $loginusername=$_POST['username'];
    if (isset($_POST['password']))$loginpassword=$_POST['password'];
    // if either isnt filled in, tell the user, a very basic bit of validation
    if (!$loginusername || !$loginpassword) $err = "please complete the form";
    if (!$err) //if no error continue
    {
    //The following bit of coding protects from MySQL injection attacks
    $loginusername = stripslashes($loginusername);
    $loginpassword = stripslashes($loginpassword);
    $loginusername = mysql_real_escape_string($loginusername);
    $loginpassword = mysql_real_escape_string($loginpassword);
    //you could add other things like check for text only blah blah
    
    $sql="SELECT * FROM $tbl WHERE username='$loginusername' and password='$loginpassword'";
    $result=mysql_query($sql);
    // Count how many results were pulled from the table
    $count=mysql_num_rows($result);
    
    // If the result equals 1, continue
    if($count==1)
    {
    	session_start();
    	$_SESSION['user'] = $loginusername; // store session data
    	//please see I have used a session variable that is generic not specific, otherwise you will have to make this page different for every user
    	//that would be a pain in the ass, you don't need to have user1 or user2, its the value stored that relevant, not what the variable name is
    	header("Location: ../{$loginusername}/index.php3");
    
    }
    else 
    {
    $err = "Wrong Username or Password";
    }
    }// end login if statement
    
    if ($err) // show error message if there is one
    {
    echo $err;
    echo "<br>Please go back in your browser and try again";
    }
    ?>
    

     

    then index.php

    <?php
    session_start(); 
    
    $loginusername = 'test2';// this is the line that would have to be diferent in every script
    //it isnt very efficient, i am actually not going to use it but delete it after you have read this.
    //what we want is a page that does the same for everyone without having to change the code.
    //so I am going to compare the stored session username against the url to check they match or else it will kick them out
    //this will however mean literally only the owner can view the page, I hope thats what you are after.
    
    $mypath = $_SERVER["REQUEST_URI"];
    //echo $mypath; // for debugging
    //now we have the path lets see if the username is in that path, i.e. test2 is inside /something/test2/index.php 
    //use the built in strpos() function, which returns position of the last occurance of the string you are looking for inside another string.
    //http://php.net/manual/en/function.strrpos.php
    
    if(strpos($mypath,"/".$_SESSION['user']."/"))//on testing it failed initially as username test is found in path /test2/ so i added the slashes to stop that. so /test/ doesnt get found in /test2/
    {
    echo "congratulations you are the right person in the right place";
    }
    else
    {
    session_destroy(); //kill the session, naughty person trying to come here
    header("Location: login.php3");
    die();// stop page executing any further
    }
    
    ?>
    
    <html>
    <body>
    
    
    </body>
    </html>
    

  8. it never knows anything, you have to tell it.  ;D

     

    lets assume the front end will only display approved items

     

    SELECT * FROM table1 WHERE `approved` = 1

     

    on the admin side do the opposite to get the unapproved ones, but if you dont want to build a backend management page, just do it directly in phpmyadmin as you stated

×
×
  • 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.