Sign in to follow this  
Zorerk

[web] PHP issues

Recommended Posts

Zorerk    109
Hello.

Having a rather odd issue here. At the moment im trying to relearn PHP as i haven't done it in a few years. And at the moment i'm creating a simple login form though i have issues with it all. After filling in the login information I end up at my sq-connect.php file but nothing is happening. All i get is a white screen. From my experience that mean that display_errors in php.ini isnt activated so it doesnt show whats wrong. That i have already checked. And i know you could insert ini_set('display_errors', 1) to show whats wrong. I have tried but still nothing.
Code is as follows bellow


Index.php
[code]
<form name="form" method="post" action="sq-connect.php">
Login: <br />
<input type="text" name="LoginUser" id="LoginUser" /><br />
Password: <br />
<input type="password" name="PasswordUser" id="PasswordUser" /><br />
<input type="submit" name="Send" id="Send" value="Faceroll" />
</form>
[/code]

sq-connect.php
[code]
<?
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);
ob_start();

// Define connection Information
$host="127.0.0.1";
$username="*****";
$password="*****";
$db_name="****";
$tbl_name="SQAccount";



// Start connection to MYSQL Server
mysql_connect("$host","$username","$password")or die("Server doesnt like what you do.");
mysql_select_db("$db_name")or die("No ice cream");

// Get info from LoginForm
$LoginUser=$_POST['LoginUser'];
$PasswordUser=$_POST['PasswordUser'];
$Encrypted_password=md5($PasswordUser);


// Check if used correct information
$sql="SELECT * FROM $tbl_name WHERE UserName='$LoginUser' and PassWord='$Encrypted_password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

if($count==1)
{
session_register("LoginUser");
session_register("PasswordUser");
header("location:opendoor.php");
}
else{
echo "Dont lie to me"
}
ob_end_flush();
?>[/code]

Anyone got a clue what im doing wrong here?

Share this post


Link to post
Share on other sites
Zorerk    109
[quote name='Sik_the_hedgehog' timestamp='1302521756' post='4797055']
Maybe I'm just being stupid, but don't you need to start with "<?php" instead of just "<?"?
[/quote]

I've used the <?php before but it didnt make any diff. Searched a little on google and found you could do <? with PHP5.

Share this post


Link to post
Share on other sites
Xycaleth    2391
The only 'major' problem I see here is that you have a missing semicolon after your echo statement:

[code]else{
echo "Dont lie to me"
}
[/code]

There's a few other problems I can see too, such as your mysql_query might be failing, or that PHP is giving an undefined index error with your $_POST variables, though most servers will just silently drop this type of error. Also the session_register function was deprecated a while ago (PHP 4.3 I think?), and you now register sessions like any other array:

[code]$_SESSION['LoginUser'] = true;
$_SESSION['PasswordUser'] = true;[/code]


And lastly, you seem to be missing a session_start() function at the top of your file, which you need to call before using any session related variables or functions. Any of these could be giving you an error.

Share this post


Link to post
Share on other sites
Zorerk    109
[quote name='rip-off' timestamp='1302527232' post='4797099']
When you fix your current problem, you should do some research on how to avoid SQL injection.
[/quote]

There is already code for it. I just excluded it as i didnt saw it relevant.

Share this post


Link to post
Share on other sites
Anntor    254
[quote name='rip-off' timestamp='1302527232' post='4797099']
When you fix your current problem, you should do some research on how to avoid SQL injection.
[/quote]

In addition to this, please use proper code style too ;) It's hard to read your code.

Example needed?
[quote name='Zorerk' timestamp='1302521123' post='4797052']
[code]
$username="*****";
$PasswordUser=$_POST['PasswordUser'];
$Encrypted_password=md5($PasswordUser);
[/code]
[/quote]

Either all lower case or all camel case or the first letter capitalized and all others not and so on.


Oh and btw, you said you see nothing (white screen). But what's up with your error file? Was it created? Is something in there?
[quote name='Zorerk' timestamp='1302521123' post='4797052']
[code]ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
[/code]
[/quote]

Share this post


Link to post
Share on other sites
Zorerk    109
[quote name='Anntor']Oh and btw, you said you see nothing (white screen). But what's up with your error file? Was it created? Is something in there?[/quote]

Nope nothing was created. I have a feeling its some kind of module I'm missing. As I'm running my own CentOS VPS that I setup on server at work (Working in the Webhosting business).

[quote name='Anntor']In addition to this, please use proper code style too ;) It's hard to read your code.[/quote]

Yea I know. Trying to make it easy to read but haven't coded properly since I was in Highschool. Thats like 6 years ago. But hopefully i'll start to code properly once i start to get things right.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this