Jump to content

Recommended Posts

??? Ok, here's my script:
[code]<?php session_start(); session_register("session"); ?>

<?php require("includes/connect/members.php"); ?>

<?php
$username = $_POST['username'];
$password = md5($_POST['password']);
if($rec=mysql_fetch_array(mysql_query("SELECT * FROM profile WHERE userid='$username' AND password = '$password'")))  {
  if(($rec['username']==$username)&&($rec['password']==$password))  {
    $_SESSION['id']=session_id();
    $_SESSION['username']=$username;
    echo "<meta http-equiv='refresh' content='0;url(http://www.eliteguards.us/index.php)'>";
    echo "<script>self.location='index.php';</script>";
  }
}
else  {
session_unset();
    echo "<meta http-equiv='refresh' content='0;url(http://www.eliteguards.us/login_false.php'>";
    echo "<script>self.location='login_false.php';</script>";
}
?>[/code]

I have no idea were I went wrong... or even if I'm close to being right at all.
When I enter my username and password it takes me to the login_false.php. And no... I'm not entering the wrong information.
Link to comment
https://forums.phpfreaks.com/topic/34458-its-not-working/
Share on other sites

This is your problem line:

[code]if($rec=mysql_fetch_array(mysql_query("SELECT * FROM profile WHERE userid='$username' AND password = '$password'")))  {[/code]

firstly you should validate your information or you will be open to sql injection attacks.

Secondly try this instead and see if it works:

[code]<?php session_start(); session_register("session"); ?>

<?php require("includes/connect/members.php"); ?>

<?php
$username = $_POST['username'];
$password = md5($_POST['password']);
$rec_check = mysql_query("SELECT * FROM profile WHERE userid='$username' AND password = '$password'");
$rec_num = mysql_num_rows($rec_check);
if($rec_num > 0)  {
$rec = mysql_fetch_array($rec_check);
  if(($rec['username']==$username)&&($rec['password']==$password))  {
    $_SESSION['id']=session_id();
    $_SESSION['username']=$username;
    echo "<meta http-equiv='refresh' content='0;url(http://www.eliteguards.us/index.php)'>";
    echo "<script>self.location='index.php';</script>";
  }
}
else  {
session_unset();
    echo "<meta http-equiv='refresh' content='0;url(http://www.eliteguards.us/login_false.php'>";
    echo "<script>self.location='login_false.php';</script>";
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/34458-its-not-working/#findComment-162313
Share on other sites

Ok, here's the code I'm using now:
[code]<?php session_start(); session_register("session"); ?>

<?php require("includes/connect/members.php"); ?>

<?php
$username = $_POST['username'];
$password = md5($_POST['password']);
$rec_check = mysql_query("SELECT * FROM profile WHERE userid='$username' AND password = '$password'");
$rec_num = mysql_numrows($rec_check);
if($rec_num > 0)  {
$rec = mysql_fetch_array($rec_check);
  if(($rec['username']==$username)&&($rec['password']==$password))  {
    $_SESSION['id']=session_id();
    $_SESSION['username']=$username;
    echo "<meta http-equiv='refresh' content='0;url(http://www.eliteguards.us/index.php)'>";
    header("Location: index.php");
  }
}
else  {
session_unset();
    echo "<meta http-equiv='refresh' content='0;url(http://www.eliteguards.us/login_false.php'>";
    header("Location: login_false.php");
}
?>[/code]
It's still taking me to the login_false.php. There's still no errors showing, it's just saying that the information put in is wrong... which it's not.
Link to comment
https://forums.phpfreaks.com/topic/34458-its-not-working/#findComment-162332
Share on other sites

[quote author=dgiberson link=topic=122693.msg506402#msg506402 date=1168981762]
Change: $rec_num = mysql_num_rows($rec_check);

To: $rec_num = mysql_numrows($rec_check);
[/quote]

[quote author=php manual]For downward compatibility, the following deprecated alias may be used: mysql_numrows()[/quote]

Why should he change valid code to a deprecated version?
Link to comment
https://forums.phpfreaks.com/topic/34458-its-not-working/#findComment-162376
Share on other sites

Another thing, if $rec_num is more than 0 you don't need the further check. Try this:

[code]<?php session_start(); session_register("session");
error_reporting(E_ALL);
?>

<?php require("includes/connect/members.php"); ?>

<?php
$username = $_POST['username'];
$password = md5($_POST['password']);
$rec_check = mysql_query("SELECT * FROM profile WHERE userid='$username' AND password = '$password'");
$rec_num = mysql_numrows($rec_check);
if($rec_num > 0)  {
    $_SESSION['id']=session_id();
    $_SESSION['username']=$username;
    echo "<meta http-equiv='refresh' content='0;url(http://www.eliteguards.us/index.php)'>";
    header("Location: index.php");
}
else  {
session_unset();
    echo "<meta http-equiv='refresh' content='0;url(http://www.eliteguards.us/login_false.php'>";
    header("Location: login_false.php");
}
?>[/code]

I also set error reporting to E_ALL so you should get some errors if something is wrong.
Link to comment
https://forums.phpfreaks.com/topic/34458-its-not-working/#findComment-162383
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.