Post: PHP/SQL error help?
02-03-2012, 02:50 PM #1
ThereThatGuy
Porkey The Pig Is My Nigg
(adsbygoogle = window.adsbygoogle || []).push({}); Hey guys,
I'm writhing a backend for my new HWID project and it seems like I've got an error.
What is happning is I am getting stuck at checklogin.php with a blank page.

My code seems to be fine but IDK,

Anyways here is the script

You must login or register to view this content.

You must login or register to view this content.

I changed the pass so don't try it Happy

If I can get any help I would be greatfull.. Thanks

Happy
:alpaca1: TTG :alpaca:
Last edited by ThereThatGuy ; 02-03-2012 at 03:52 PM.
02-03-2012, 06:01 PM #2
Epic?
Awe-Inspiring
Originally posted by ThereThatGuy View Post
Hey guys,
I'm writhing a backend for my new HWID project and it seems like I've got an error.
What is happning is I am getting stuck at checklogin.php with a blank page.

My code seems to be fine but IDK,

Anyways here is the script

You must login or register to view this content.

You must login or register to view this content.

I changed the pass so don't try it Happy

If I can get any help I would be greatfull.. Thanks

Happy
:alpaca1: TTG :alpaca:


I don't know about other people, but I'm not going to be wasting my time diggging through your entire project for the bug. You should either post an You must login or register to view this content. or learn to debug yourself (which I would recommend).

And you haven't told us anything other than checklogin.php has a blank page, you haven't told us what it should do.
Last edited by Epic? ; 02-03-2012 at 06:06 PM.

The following user thanked Epic? for this useful post:

ThereThatGuy
02-03-2012, 08:17 PM #3
ThereThatGuy
Porkey The Pig Is My Nigg
Originally posted by Epic
I don't know about other people, but I'm not going to be wasting my time diggging through your entire project for the bug. You should either post an You must login or register to view this content. or learn to debug yourself (which I would recommend).

And you haven't told us anything other than checklogin.php has a blank page, you haven't told us what it should do.


You're right sorry, Should have told people,
Anyways It's just for setting a session and then redirecting to index.php. For some reason it is not starting a session, or giving me an error. So I assume that it is somewhere within this, This is my first "real" PHP/MySQL project so I'm running into some problems.

    
<?php
$host="mysql2.000webhost.com"; // Host name
$username="a7759150_Admin"; // Mysql username
$password="michael1"; // Mysql password
$db_name="a7759150_HWID"; // Database name
$tbl_name="members"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("myusername");
session_register("mypassword");
header("location:index.php");
}


Thanks for the link for the SSCCE, Looking at it now Happy
Last edited by ThereThatGuy ; 02-03-2012 at 08:23 PM.
02-04-2012, 05:49 AM #4
Epic?
Awe-Inspiring
Originally posted by ThereThatGuy View Post
You're right sorry, Should have told people,
Anyways It's just for setting a session and then redirecting to index.php. For some reason it is not starting a session, or giving me an error. So I assume that it is somewhere within this, This is my first "real" PHP/MySQL project so I'm running into some problems.

    
<?php
$host="mysql2.000webhost.com"; // Host name
$username="a7759150_Admin"; // Mysql username
$password="michael1"; // Mysql password
$db_name="a7759150_HWID"; // Database name
$tbl_name="members"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("myusername");
session_register("mypassword");
header("location:index.php");
}


Thanks for the link for the SSCCE, Looking at it now Happy


Alright... So, you redirect to index.php when you call header("location:index.php") (small nitpick: use single-quotes for strings that don't contain variables, it's slightly more efficient and proves that no variable is intended to be there if your code is later reviewed). Now, the redirect code is actually a subordinate statement of an if-statement, the condition being $count == 1. This means that if the redirect code isn't being executed, then $count is not equal to one. Therefore, $count is either greater than, or less than 1 (just guessing, it's probably 0, or it's more than 1).

That means you should figure out the value of $count (run it through a debugger, or just echo it out before the if-statement).

The following user thanked Epic? for this useful post:

ThereThatGuy

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo