# [web] PHP issues

This topic is 2601 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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
 <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> 

sq-connect.php
 <? 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(); ?>

Anyone got a clue what im doing wrong here?

##### Share on other sites
Maybe I'm just being stupid, but don't you need to start with "<?php" instead of just "<?"?

##### Share on other sites

Maybe I'm just being stupid, but don't you need to start with "<?php" instead of just "<?"?

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 on other sites
The only 'major' problem I see here is that you have a missing semicolon after your echo statement:

else{ echo "Dont lie to me" } 

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: $_SESSION['LoginUser'] = true; $_SESSION['PasswordUser'] = true; 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 When you fix your current problem, you should do some research on how to avoid SQL injection. #### Share this post ##### Link to post ##### Share on other sites When you fix your current problem, you should do some research on how to avoid SQL injection. 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 When you fix your current problem, you should do some research on how to avoid SQL injection. In addition to this, please use proper code style too It's hard to read your code. Example needed? $username="*****"; $PasswordUser=$_POST['PasswordUser']; $Encrypted_password=md5($PasswordUser); 

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?

ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); 

##### Share on other sites

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).

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.

• 16
• 9
• 13
• 41
• 15