Jump to content

Isset


9tglhe6nwj

Recommended Posts

I believe that my problem is with the isset on line 7 and 39, but I do not know of anyway around it. Can someone enlighten me.

<?php
session_start();
if (isset($_GET['logout'])){
    unset($_SESSION['logged_in']);
}
?>
<html>
    <head>
        <title>Add a New Car!</title>
        <?php
        if (isset($_POST['submit'])) {
            //print_r($_POST);
            $password = md5($_POST['password']);
            //echo'<p>'.$password.'</p>';
            $username = ($_POST['username']);
            //echo'<p>'.$username.'</p>';
        }
        $db = new PDO('sqlite:login.sqlite');
        $login = 'SELECT * FROM login
        WHERE userid="'.$username.'"
        AND password="'.$password.'";';
        //echo'<p>'.$login.'</p>';
        $attempt = $db->query($login);
        foreach ($attempt as $row) {
        //print_r($row);
        $_SESSION['logged_in'] = $username;
        }
        ?>
    </head>
    <body>
                <?php 
        if (!isset($_SESSION['logged_in'])){
        ?>
            <form method="post" action="Db_login.php">
            <p>Username:<br /><input type="text" name="username" /> </p>
            <p>Password:<br /><input type="password" name="password" /></p>
            <p><input type="submit" name="submit" value="Log In!" /></p>
            </form>
        <?php
        } else {
        ?>
        <?php
        if(isset($_POST['submit'])) {
            print_r($_POST);
            $make = ($_POST['make']);
            $model = ($_POST['model']);
            $year = ($_POST['year']);
            $fuel = ($_POST['fuel_type']);
            $vin = ($_POST['vin_number']);
            $reg = ($_POST['reg_number']);
        }
        $db = new PDO('sqlite:cars.sqlite');
        $sqlCars = 'INSERT INTO cars ( )
        VALUES("'.$make.'","'.$model.'","'.$year.'","'.$fuel.'","'.$vin.'","'.$reg.'");';
        echo'<p>'.$sqlCars.'</p.>';
        ?>
        <form method="post" action="Db_new_Cars.php" enctype="multipart/form-data">
            <p>Make:<br /><input type="text" name="make" /> </p>
            <p>Model:<br /><input type="text" name="model" /></p>
            <p>Year:<br /><input type="text" name="year" /></p>
            <p>Fuel Type:<br /><input type="text" name="fuel_type" /></p>
            <p>Vin Number:<br /><input type="text" name="vin_number" /></p>
            <p>Reg Number:<br /><input type="text" name="reg_number" /></p>
            <p>Choose a image to upload:<br />
            <input type="file" name="myfile"></input></p>
            <p><input type="submit" name="submit" value="Submit!" /></p>
        </form>
        <h1> Protected Content!</h1>
        <p>You are logged in as <em><?php echo $_SESSION['logged_in']; ?> </em></p>
        <p><a href="Db_login.php?logout=true">Log out!</a></p>
        <p><a href="New_Cars.php">Add a new car</a></p>
        <p><a href="Book_Out_Cars.php">Book out a car</a></p>
        <?php
        }
        ?>

    </body>
</html>

Link to comment
Share on other sites

You've got two buttons called "submit" there.  Rather than using isset(), you might want to check if $_POST['submit'] == 'Log In!' or if it == 'Submit!'.

 

Also those forms there point to two different scripts, though it looks like this script handles both of them.  What's going on there?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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