Jump to content

9tglhe6nwj

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

9tglhe6nwj's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ohhh sorry I didn't think to explain >.< /facepalm. Anyway the problem is I login, then when I go to submit the second form it refreshes the page and I'm logged out again.
  2. 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>
  3. Okay, so below I have posted my code, the problem I am having is not knowing how PDO works that well. So what I have attempted to do here is use SQL to check if the user and password are correct, but I'm not sure how to carry on. I realize I have to determine if the database found the matching password and/or username but I have no idea how, any help will be much appreciated. <html> <head> <title>Database login</title> <?php if (isset($_POST['submit'])) { print_r($_POST); $password = md5($_POST['password']); echo'<p>'.$password.'</p>'; $username = ($_POST['username']); echo'<p>'.$username.'</p>'; } ?> </head> <body> <?php $db = new PDO('sqlite:login.sqlite'); $login = 'SELECT * FROM login WHERE userid="'.$username.'" AND password="'.$password.'";'; echo'<p>'.$login.'</p>'; $attempt = $db->query($login); ?> <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> </body> </html>
×
×
  • 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.