can anyone tell me why this is wrong? (im sure that ive debugged everything)
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
//check database for user and verify password
$dbuname = $_REQUEST['uname'];
$dbh=mysql_connect ("localhost", "my_username", "my_password") or die ('I cannot connect to the database because: ' . mysql_error());
@mysql_select_db ("my_database");
$query = "SELECT * FROM _user WHERE (username='$dbuname')";
$result = mysql_query($query);
$ifExists = mysql_num_rows($result);
if (ifExists == 1)
{
$username = mysql_result($result, 1, "username");
$password = mysql_result($result, 1, "password");
if ($password == $_POST['pword'])
{
$_SESSION['user'] = isLogged;
header("Location: <!-- m --><a class="postlink" href="http://www.whiteazn.com/satworld/main.php">http://www.whiteazn.com/satworld/main.php</a><!-- m -->");
}
else
{
$_SESSION['user'] = notLogged;
$_SESSION['invalid'] = 1;
header("Location: <!-- m --><a class="postlink" href="http://www.whiteazn.com/satworld/admin/">http://www.whiteazn.com/satworld/admin/</a><!-- m -->");
}
}
else
{
$_SESSION['user'] = notLogged;
$_SESSION['invalid'] = 1;
header("Location: <!-- m --><a class="postlink" href="http://www.whiteazn.com/satworld/admin/">http://www.whiteazn.com/satworld/admin/</a><!-- m -->");
}
?>
it connects to the database, but doesnt get anything to the database (ifExists is 0 after it does the query)
i go to my database and run the same command and i get results.
i cant figure this one out at allTry adding this after mysql_query()
while (list($var1,$var) =
mysql_fetch_row($result)) {
Now replace $var1, $var with your own;
it names the colums of the mysql table
from first to last (that you call on).
Here's a example snippet...
$query = "SELECT id, name FROM table";
$result = mysql_query("$query");
while (list($id,$name) =
mysql_fetch_row($result)) {
echo "Since I named the first one $id then I use $id for the id colum data (to show it)";
echo "Same thing goes for $name !";
}
Hope that helps...wish you posted 5 min earlier than you did
i found the error
2 things ...
when it fetches, it starts at 0, not 1, as i posted here
$username = mysql_result($result, 1, "username");
$password = mysql_result($result, 1, "password");
2nd, not sure if it made a difference (as i changed it from 1 to 0 and it worked fine? or i was hallucinating)
if (ifExists == 1)
should be
if ($ifExists == 1)
now, i just got some other weird questions (not related to this, so posted in another thread)$_SESSION['user'] = notLogged;
those have to be in quotes
$_SESSION['user'] = 'notLogged';
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
//check database for user and verify password
$dbuname = $_REQUEST['uname'];
$dbh=mysql_connect ("localhost", "my_username", "my_password") or die ('I cannot connect to the database because: ' . mysql_error());
@mysql_select_db ("my_database");
$query = "SELECT * FROM _user WHERE (username='$dbuname')";
$result = mysql_query($query);
$ifExists = mysql_num_rows($result);
if (ifExists == 1)
{
$username = mysql_result($result, 1, "username");
$password = mysql_result($result, 1, "password");
if ($password == $_POST['pword'])
{
$_SESSION['user'] = isLogged;
header("Location: <!-- m --><a class="postlink" href="http://www.whiteazn.com/satworld/main.php">http://www.whiteazn.com/satworld/main.php</a><!-- m -->");
}
else
{
$_SESSION['user'] = notLogged;
$_SESSION['invalid'] = 1;
header("Location: <!-- m --><a class="postlink" href="http://www.whiteazn.com/satworld/admin/">http://www.whiteazn.com/satworld/admin/</a><!-- m -->");
}
}
else
{
$_SESSION['user'] = notLogged;
$_SESSION['invalid'] = 1;
header("Location: <!-- m --><a class="postlink" href="http://www.whiteazn.com/satworld/admin/">http://www.whiteazn.com/satworld/admin/</a><!-- m -->");
}
?>
it connects to the database, but doesnt get anything to the database (ifExists is 0 after it does the query)
i go to my database and run the same command and i get results.
i cant figure this one out at allTry adding this after mysql_query()
while (list($var1,$var) =
mysql_fetch_row($result)) {
Now replace $var1, $var with your own;
it names the colums of the mysql table
from first to last (that you call on).
Here's a example snippet...
$query = "SELECT id, name FROM table";
$result = mysql_query("$query");
while (list($id,$name) =
mysql_fetch_row($result)) {
echo "Since I named the first one $id then I use $id for the id colum data (to show it)";
echo "Same thing goes for $name !";
}
Hope that helps...wish you posted 5 min earlier than you did
i found the error
2 things ...
when it fetches, it starts at 0, not 1, as i posted here
$username = mysql_result($result, 1, "username");
$password = mysql_result($result, 1, "password");
2nd, not sure if it made a difference (as i changed it from 1 to 0 and it worked fine? or i was hallucinating)
if (ifExists == 1)
should be
if ($ifExists == 1)
now, i just got some other weird questions (not related to this, so posted in another thread)$_SESSION['user'] = notLogged;
those have to be in quotes
$_SESSION['user'] = 'notLogged';