Jump to content

It's not working!


Zoud

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

Archived

This topic is now archived and is closed to further replies.

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