But the file is on the server? and the forms action is “login.php” it was “checklogin.php” but i changed it to see if their was problems with that particular name, but nope, same error
OK do this… comment out your entire check login script and replace it with this.
[php]
if you get a connected to database message then go back to the form and just hit submit if you get the same connected message then your two files are properly connected if you get the same error the issue is with your file locations or permissions.
Side note you have an errant echo line in your if than statement.
it works with just that code! YAY!
The code you posted is all jacked up… oh no where do you actually select a table or connect the query to the connection try this code.
[php]<?php
$con = mysql_connect(“127.0.0.1”,“AdminChris”,“mobile”);
if (!$con) {
die('Could not connect: ’ . mysql_error());
} else {
echo “Connected to Database”;
}
$query = mysql_query(“SELECT * FROM Main WHERE username=’$username’”);
$numrows = mysql_num_rows($query);
if($numrows !=0) {
while ($rows = mysql_fetch_array($query)) {
$dbusername = $row [‘username’]
$dbpassword = $row [‘password’]
if (($username==$dbusername) && ($password==$dbpassword)) {
$_SESSION[‘username’]=$dbusername;
} else {
die (“Login Unsuccessful”);
}
}
} else {
die (“please enter user and pass”);
}
?>[/php]
give that a try and let me know
same error
used the online checker again:
came out with:
PHP Syntax Check: Parse error: syntax error, unexpected T_VARIABLE in your code on line 16
which one is line 16 in your script?
$dbpassword = $row [‘password’]
Your missing semicolons ;;;;;;;;;;;;;; check your semicolons
Its working!
however it’s not coming up with: please enter user and pass
so is it not accessing a array from the table? or is it because i haven’t started a session?
try adding this line
[php] mysql_select_db(‘YOUR DATABASE NAME’) or die(“Unable to select database”);
[/php]
Same result, current code:
[php]<?php
$con = mysql_connect(“127.0.0.1”,“AdminChris”,“mobile”);
mysql_select_db(‘Users’) or die(“Unable to select database”);
if (!$con) {
die(‘Could not connect: ’ . mysql_error());
} else {
echo “Connected to Database”;
}
$query = mysql_query("SELECT * FROM Main WHERE username=’$username’");
$numrows = mysql_num_rows($query);
if($numrows !=0) {
while ($rows = mysql_fetch_array($query)) {
$dbusername = $row [‘username’];
$dbpassword = $row [‘password’];
if (($username==$dbusername) && ($password==$dbpassword)) {
$_SESSION[‘username’]=$dbusername;
} else {
die (“Login Unsuccessful”);
}
}
} else {
die (“please enter user and pass”);
}
?>[/php]
‘Connected to Databaseplease enter user and pass’ is the message on the page
your sql query is not returning any rows so its working its just sending you the error of no rows.
DOH!
Put this back in to the code I removed it when we were testing database connection
At the top
[php]session_start();
$username = $_POST[‘username’];
$password = $_POST[‘password’];
[/php]
Add a login successful echo in the if then statement so that you know it works.
Not sure if this is correct? i added in the echo and session start, however it is still coming up with ‘Connected to Databaseplease enter user and pass’
Current Code:
[php]<?php
session_start();
$username = $_POST[‘username’];
$password = $_POST[‘password’];
$con = mysql_connect(“127.0.0.1”,“AdminChris”,“mobile”);
mysql_select_db(‘Users’) or die(“Unable to select database”);
if (!$con) {
die(‘Could not connect: ’ . mysql_error());
} else {
echo “Connected to Database”;
}
$query = mysql_query("SELECT * FROM Main WHERE username=’$username’");
$numrows = mysql_num_rows($query);
if($numrows !=0) {
while ($rows = mysql_fetch_array($query)) {
$dbusername = $row [‘username’];
$dbpassword = $row [‘password’];
if (($username==$dbusername) && ($password==$dbpassword)) {
$_SESSION[‘username’]=$dbusername;
echo (“Login Succesful”);
} else {
die ("Login Unsuccessful");
}
}
} else {
die (“please enter user and pass”);
}
?>[/php]
First you never connected your mysql_query statement to the database connection try it like this, it is a little cleaner replace this [php]$query = mysql_query(“SELECT * FROM Main WHERE username=’$username’”);
[/php] with this
[php]$sql = “SELECT * FROM Main WHERE username=’$username’”;
$query = mysql_query($sql, $con) or die(mysql_error($con));;
[/php]
and hurry cause I have to go again and I think we are almost done here.
Same result, this is my first php based code, so i’m a rookie.
[php]<?php
session_start();
$username = $_POST[‘username’];
$password = $_POST[‘password’];
$con = mysql_connect(“127.0.0.1”,“AdminChris”,“mobile”);
mysql_select_db(‘Users’) or die(“Unable to select database”);
if (!$con) {
die(‘Could not connect: ’ . mysql_error());
} else {
echo “Connected to Database”;
}
$sql = "SELECT * FROM Main WHERE username=’$username’";
$query = mysql_query($sql, $con) or die(mysql_error($con));;
$numrows = mysql_num_rows($query);
if($numrows !=0) {
while ($rows = mysql_fetch_array($query)) {
$dbusername = $row [‘username’];
$dbpassword = $row [‘password’];
if (($username==$dbusername) && ($password==$dbpassword)) {
$_SESSION[‘username’]=$dbusername;
echo (“Login Succesful”);
} else {
die ("Login Unsuccessful");
}
}
} else {
die (“please enter user and pass”);
}
?>[/php]
I forgot to add the database connection to the database select line.
[php] mysql_select_db(‘Users’, $con) or die(“Unable to select database”);
[/php]