I'm a member of the Society for Technical Communication, and I volunteered to build a PHP-driven site for my chapter for free because I feel that the opportunity will help me become a better PHP programmer.
I've been doing fine so far, but I've hit a problem on the php login script that I plan to implement in various ways throughout the project. Basically, when I try to log in with a member profile that I KNOW FOR SURE is in the MYSQL database I set up, the script still can't find the login info in the table and executes the unsuccessful login code instead.
To try this for yourself, go to ocstc.net and try logging in with username "Neo" and password "theone".
The script currently runs without throwing any errors, but it still doesn't work right and I've been fighting with it for a week.
Here's my code:
[php]
<?php include("header.php"); ?>
<?php
// Login Script version 0.0.7
// Get our form data
$user = trim($_POST[username]);
$pass = trim($_POST[password]);
// define our database parameters
$dbhost = 'localhost';
$dbuser = [censored] // My supervisor won't let me give this info out
$dbpass = [censored] // Not this one either
if ($user && $pass) {
// make the connection, or die trying
$con = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error: Could not connect to database');
$dbname = 'ocstcnet_main';
mysql_select_db($dbname);
$result = ("SELECT * FROM members WHERE username='$user' AND password='$pass'");
mysql_query($result);
if ($user == $result['username'] && $pass == $result['password']){
echo "Username is good; further content can be added";
}
else{
$error2 = "<br>";
$error2 .= "<h2>Error</h2>";
$error2 .= "<br>";
$error2 .= "<div class='php_output'>The username <b><i>". $user . "</i></b> and password <b><i>" . $pass . "</i></b> is not in the database.</div>";
$error2 .= "<br>";
echo $error2;
}
}
else {
$error1 = "<br>";
$error1 .= "<h2>Error</h2>";
$error1 .= "<br>";
$error1 .= "<div class='php_output'>You must fill in all fields!</div>";
echo $error1;
}
?>
<?php include("footer.php"); ?>
[/php]
If I can get help, I will credit anyone who can solve this in the source code.
I've been doing fine so far, but I've hit a problem on the php login script that I plan to implement in various ways throughout the project. Basically, when I try to log in with a member profile that I KNOW FOR SURE is in the MYSQL database I set up, the script still can't find the login info in the table and executes the unsuccessful login code instead.
To try this for yourself, go to ocstc.net and try logging in with username "Neo" and password "theone".
The script currently runs without throwing any errors, but it still doesn't work right and I've been fighting with it for a week.
Here's my code:
[php]
<?php include("header.php"); ?>
<?php
// Login Script version 0.0.7
// Get our form data
$user = trim($_POST[username]);
$pass = trim($_POST[password]);
// define our database parameters
$dbhost = 'localhost';
$dbuser = [censored] // My supervisor won't let me give this info out
$dbpass = [censored] // Not this one either
if ($user && $pass) {
// make the connection, or die trying
$con = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error: Could not connect to database');
$dbname = 'ocstcnet_main';
mysql_select_db($dbname);
$result = ("SELECT * FROM members WHERE username='$user' AND password='$pass'");
mysql_query($result);
if ($user == $result['username'] && $pass == $result['password']){
echo "Username is good; further content can be added";
}
else{
$error2 = "<br>";
$error2 .= "<h2>Error</h2>";
$error2 .= "<br>";
$error2 .= "<div class='php_output'>The username <b><i>". $user . "</i></b> and password <b><i>" . $pass . "</i></b> is not in the database.</div>";
$error2 .= "<br>";
echo $error2;
}
}
else {
$error1 = "<br>";
$error1 .= "<h2>Error</h2>";
$error1 .= "<br>";
$error1 .= "<div class='php_output'>You must fill in all fields!</div>";
echo $error1;
}
?>
<?php include("footer.php"); ?>
[/php]
If I can get help, I will credit anyone who can solve this in the source code.