Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKonrad Pilch
2,435 PointsPHP
HI,
WHats wrong with this PHP code?
<?php
error_reporting(E_ALL & ~E_NOTICE);
session_start();
if($_POST['submit']) {
include_once("connection.php");
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
$sql = "SELECT id, username, password FROM members WHERE username = 'username'AND activated = '1' LIMIT 1";
$query = mysqli_query($dbCon, $sql);
if($query) {
$row = mysqli_fetch_row($query);
$userId = $row[0];
$dbUsername = $row[1];
$dbPassword = $row[2];
}
if ($username == $dbUsername && $password == $dbPassword) {
$_SESSION['username'] = $username;
$_SESSION['id'] = $userId;
header('Location: user.php');
} else {
echo "Incorrect username or password.";
}
}
?>
<!DOCTYPE>
<html>
<head>
<title>PHP/MySQL Login</title>
</head>
<body>
<h1>PHP/MySQL Login</h1>
<form method="post" action"index.php">
<input type="text" placeholder="Username" name="username" /> <br />
<input type="password" placeholder="Password" name="password" /> <br />
<input type="submit" name"submit" value"Log In" />
</form>
</body>
</html>
2 Answers
Christian Andersson
8,712 PointsJust looked this one over briefly, but don't you need to have isset
?
if(isset($_POST['submit']))
update:
looks like you missed an equal-sign in your html :)
form method="post" action="index.php"
Konrad Pilch
2,435 PointsCould you help me with this one please?
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsI tried even this :
It doesn't work.
Christian Andersson
8,712 PointsChristian Andersson
8,712 PointsUpdated my answer above.
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsLallll xd such a simple mistake : p
Thank you very much!
lol thats funny, i though u said submit. i missed a = in my submit name too xdd
My prev code was
<input type="submit" name<here>"submit" value"Log In" />
i corrected it
and i missed it even in my Log In : p
Thank you very much! I make sure i look on html next time too xd