Thread: Newbiee Gah
View Single Post
Old 12-04-2007, 10:09 PM   #1 (permalink)
Tanax
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default Newbiee Gah

Seriously.. I'm going NUTS :|

Mom wants me in bed, but I wanna get this script to work, but it doesn't and I'm stressed, and I can't for the love of god(!!!) find the error.

php Code:
<?php

/**
 * @author Tanax
 * @copyright 2007
 */

    include('config.php');
    include('header.php');
   
    mysql_connect('localhost', 'root', '');
    mysql_select_db('lemons')
   
    if(isset($_SESSION['logged'])) {
       
        if($_POST['submit']) {
           
            $who = $_POST['who'];
            $meeting = $_POST['meeting'];
            $protocol = $_POST['protocol'];
               
            $query = mysql_query("  INSERT INTO
                                        `protocol`
                                    SET
                                        `p_who` = '"
.$who."',
                                        `p_meeting` = '"
.$meeting."',
                                        `p_protocol` = '"
.$protocol."'
                                           
                                    "
);
                                       
            if($query) {
                   
                echo 'Protokoll tillagt!';
                echo '<br /><a href="insert.php">Lägg till flera</a>';
                   
            }
               
            else {
                   
                echo 'Nåt gick fel!';
                   
            }
               
        }
           
        else {
           
            ?>
               
            <form action="insert.php" method="POST">
            <h3>Vilka:</h3><br />
            <input name="who" type="text" /><br />
            <h3>När:</h3><br />
            <input name="meeting" type="text" /><br />
            <h3>Protokoll:</h3><br />
            <textarea name="protocol" cols="60" rows="20"></textarea><br />
            <input type="submit" name="submit" value="Lägg till!" />
            </form>
                   
            <?php
           
        }
       
    }
   
    else {
   
        if($_POST['auth']) {
           
            $user = $_POST['user'];
            $pass = $_POST['pass'];
           
            if($user != $admin || $pass != $password) {
               
                echo 'Användarnamn eller lösenord är inkorrekt!';
                echo '<br /><a href="insert.php">Försök igen</a>';
               
            }
           
            else {
           
                $_SESSION['logged'] = 'yes';
               
                if(isset($_SESSION['logged'])) {
                   
                    echo 'Du har nu loggats in! Klicka på <a href="insert.php">denna</a> länk för att lägga till protokoll!';
           
                }
               
                else {
                   
                    echo 'Något gick fel i inloggningsprocessen!';
                   
                }
               
            }
       
        }
       
        else {
           
            ?>
           
            <form action="insert.php" method="POST">
            <h3>Användarnamn:</h3><br />
            <input name="user" type="text" /><br />
            <h3>Lösenord:</h3><br />
            <input name="pass" type="text" /><br />
            <input type="submit" name="auth" value="Logga in!" />
            </form>
           
           
            <?php
           
        }
       
    }
       
    include('footer.php');

?>

Yes, it's a really basic script. I'm only using it for a small site, so I don't use a user system in the database.

I store the admin password and the username in the config.

The messages are in swedish, but I'm pretty sure you can figure out what they mean based on the coding.

The error is that I login, and it echo's "You are logged in, click her to add a protocol", and when I do that, the
PHP Code:
if(isset($_SESSION['logged'])) 
should execute, since I've set the session...
I actually even check before it links me to the same page, that the session is set, and it only echoes the "you are logged in.." if the session is set.

Yet, it doesn't work. When I'm logged in, and click the link, I still get to see the login form -.-

I know this is a very.. insecure script. But it's really a SMALL website, and the ones that are viewing it, doesn't have a clue what website programming is, nonetheless hacking. So yea...

Anyways, please help me :((( You are my only hooooope xD haha
Tanax is offline  
Reply With Quote