Jump to content

White_Lily

Members
  • Posts

    531
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by White_Lily

  1. Here is some simple form and validation:

     

    <html>
    <head>
    
    </head>
    <body>
    
    <?php
    
    //Variables holding the post values
    $submit = $_POST["submit"];
    $username = mysql_real_escape_string($_POST["username"]);
    $password = mysql_real_escape_string($_POST["password"]);
    
    //Runs this if the form was submitted
    if($submit){
    
    //checks if the form was empty or not
    if(!$username && !$password){
     $msg = "The form was submitted empty.";
    }else{
    
     //checks to make sure a username was entered
     if(!$username){
     $msg .= "Please enter a username.";
     }else{
    
     //checks to make sure a password was entered
     if(!$password){
     $msg .= "Please enter a password.";
     }else{
     $query = mysql_query("SELECT * FROM members");//Queries the database
     $num = mysql_num_rows($query);//Collects the rows (if any)
     $row = mysql_fetch_assoc($query);//a variable to grab rows with
    
     //checks if there are any registered members
     if($num == 0){
     $msg .= "There are no members in the database, register first.";
     }else{
     //if there are members this checks the entered username against those in the database
     if($row["username"] != $username){
    	 $msg .= "The username does not match any registered members.";
     }else{
    	 //if there are members this checks the entered password against those in the database
    	 if($row["password"] != $password){
    	 $msg .= "The password does not match any registered members.";
    	 }else{
    
    	 //if everything succeeds then the sessions will start
    	 session_start();
    	 $_SESSION["username"] = $username;
    	 $_SESSION["password"] = $password;
    
    	 //re-directs the user to the home page.
    	 header("Location: index.php");
    	 }
     }
     }
     }
     }
    }
    echo $msg;
    }
    
    ?>
    
    <form action="" method="POST">
    <label>Username:</label>
    <input type="text" name="username" />
    <label>Password:</label>
    <input type="password" name="password" />
    <input type="submit" name="submit" value="Login" />
    </form>
    </body>
    </html>
    

     

    Remember: if the user has logged in you need to carry over the sessions to every single page on the website,

     

    this is done at the very top of the source code (before the doctype):

     

    <?php
    session_start();
    $username = $_SESSION["username"];
    $password = $_SESSION["password"];
    ?>
    

  2. As for the directory being specified, you have done it slightly wrong - you are using xampp, this means that htdocs (to a browser) doesnt technically exist and is replaced with "http://localhost/siteName" to prove this, echo this out:

     

    $filename = $_SERVER["DOCUMENT_ROOT"];
    
    echo $filename;
    

     

    This means this line:

     

    $directory = 'C:\Users\test\Desktop\Main\xampp\htdocs\mp3';
    

     

    Should be:

     

    $directory = $_SERVER["DOCUMENT_ROOT"]."/mp3/";
    

  3. If the table is being found in the database try echoing the rows:

     

    $num = mysql_num_rows($issues);
    
    echo $num;
    

     

    If it echos nothing (not even a 0) then your query is probably the problem, if it echos '0' then its saying you have no entries, anything higher and the problem is elsewhere.

  4. Your not out of line - once ive finished developing it and its fully pre-live checked and post-live checked i will post a link :)

     

    A CMS should be capable of development throughout its life-time, this means that you should be about to take away features and add features depending on your sites needs. This is the one reason why i hate pre-built CMS's such as WordPress, and Joomla. Very difficult to customise those. (sets my teeth on edge just mentioning them >_<)

  5. Hi,

     

    I tried writing some code for my navigation menu to make it easier on my part (with creating the site etc).

     

    I have written this so far:

     

    
    <?php
    
    $nav = select("*", "navigation", NULL, NULL, NULL);
    $num = mysql_num_rows($nav);
    $get = mysql_fetch_assoc($nav);
    $filename = file_exists($_SERVER["DOCUMENT_ROOT"]."forum/".$get["file_path"]);
    
    if($num > 0){
    while($get = mysql_fetch_assoc($nav)){
    if($filename){
    
    $path = $GLOBALS["siteUrl"].$get["file_path"];
    
    
    
    echo '<li><a href="'.$path.'">'.$get["page_name"].'</a></li>';
    }
    }
    }else{
    echo "<li>Could not find a navigation menu.</li>";
    }
    
    ?>
    

     

    Problem is, even though there is an entry in the database (to a page that DOES exist) nothing shows in the navigation area, can't think why.

     

    Any help would be appreciated.

  6. could check to see if the field is empty?

     

    The HTML:

     

    <html>
    <form action="" method="POST" enctype="multipart/form-data">
    <label>File Upload</label><input type="file" name="file" />
    <input type="submit" name="submit" value="Upload" />
    </form>
    </html>
    

     

    The PHP:

     

    <?php
    if(!$_POST["file"]){
    echo "No file selected.";
    }else{
    
    //processing code
    
    }
    ?>
    

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