TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Newbiee Gah (http://www.talkphp.com/absolute-beginners/1609-newbiee-gah.html)

Tanax 12-04-2007 10:09 PM

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

Swordbeta 12-04-2007 10:16 PM

First of all,you keep repeating <?php,you need to use this one.
I can't really say what's wrong since I don't speak your language but this is at least what I can say:
PHP Code:

if(isset($_POST['submit'])){ 

And I'm also not sure about the query:
PHP Code:

$query mysql_query("  INSERT INTO `protocol` SET `p_who` = '$who',`p_meeting` ='$meeting',`p_protocol` ='$protocol'"); 


Wildhoney 12-04-2007 10:19 PM

In addition to Swordbeta's post, I don't see a session_start() call in that script:

php Code:
<?php

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


    session_start();

    include('config.php');
    include('header.php');
   
    mysql_connect('localhost', 'root', '');
    mysql_select_db('lemons')

    ...

Tanax 12-05-2007 05:55 AM

Quote:

Originally Posted by Swordbeta (Post 5300)
First of all,you keep repeating <?php,you need to use this one.
I can't really say what's wrong since I don't speak your language but this is at least what I can say:
PHP Code:

if(isset($_POST['submit'])){ 

And I'm also not sure about the query:
PHP Code:

$query mysql_query("  INSERT INTO `protocol` SET `p_who` = '$who',`p_meeting` ='$meeting',`p_protocol` ='$protocol'"); 


Thanks, but it shouldn't be a problem, since checking for $_POST['submit'] is the same as checking if it's set o.O

THe query was no problem :) It's working ^^

Quote:

Originally Posted by Wildhoney (Post 5303)
In addition to Swordbeta's post, I don't see a session_start() call in that script:

php Code:
<?php

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


    session_start();

    include('config.php');
    include('header.php');
   
    mysql_connect('localhost', 'root', '');
    mysql_select_db('lemons')

    ...

OFCOURSE!!! It works now :D:D Wieee, thanks Adam! <3


All times are GMT. The time now is 01:17 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0