Jump to content

[SOLVED] Login problem


rnintulsa

Recommended Posts

I am trying to learn php.  In this case a simple login with sessions.

 

My php login works on my local machine but when I try to run the pages on the server it doesn't work.

Not sure if the problem is mysql related or php.

 

This is the code

<?php
session_start( );

// if username and password are set and not empty then proceed with the rest of the process
if( isset( $_POST[ 'username' ] ) && isset( $_POST[ 'password' ] ) && $_POST[ 'username' ] != '' && $_POST[ 'password' ] != '' )
{
	$username = $_POST['username'];
	$password = $_POST['password']; 

	//@ $db = new mysqli( 'mysql.kdesigns.net', 'username', 'password', 'dbname' );
	@ $db = new mysqli( 'localhost', 'root', 'rn2846', 'kdesignsOrion' );
	//dbet.valueweb.net
	if( mysqli_connect_errno( ) )
	{
		echo"Connection to the database failed. Please try again later." ;			
		exit;
	}

	//checks for username and password in db table.
   	$results = $db->query( "select * from users where username='" . $username . "' and password = '" . $password . "'" );

	//greater than zero		
	if( $results->num_rows > 0 )
	{
		$_SESSION['username'] = $username;  
		//redirect

	}
	else
	{
		echo 'You must be registered before you may log in.';
	}
}
?>
<html>
<head>

<title>KDesign</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link type="text/css" rel="stylesheet" href="css/kdesign.css"/>
</head>
<body>
<div id="container">

	<div id="header">
		<img src="images/logo_sm.gif">
		<p>
			TULSA, OKLAHOMA<br><br>
			ADDRESS<br><br>
			PHONE: 918.810.0391<br><br>
			<a href="mailto:mail@kdesigns.net?subject=Kdesign">MAIL@KDESIGNS.NET</a><br>
		</p>
	</div>			

		<div id="top_nav">
			<a href="default.htm">HOME</a>    <span class="rd_bld">|</span>    
			<a href="services.htm">SERVICES</a>    <span class="rd_bld">|</span>    
			<a href="portfolio.htm">PORTFOLIO</a>    |    
			<a href="contact.htm">CONTACT</a>    <span class="rd_bld">|</span>    
			<a href="clients.htm"><span class="rd_bld">CLIENT ENTRANCE</span></a>
		</div>

			<div id="left_nav">
				<a href="login_orion.php">Orion</a><br><br>
				<a href="#nogo">Client 2</a><br><br>
				<a href="#nogo">Client 3</a><br><br>
				<a href="#nogo">Client 4</a><br><br>

			</div>

				<div id="center_column">

					<?php
						include( 'sessions.php' );
						show_statement( );

						if (isset($_SESSION['username'])) 
						{ 
							echo '<br />';
							echo 'Log '.$_SESSION['username'].'';		
							echo '<br /><a href="logout.php">Log out</a><br />';
						}
						else
						{
							echo 'Could not log you in<br />';
						}
					?>

					<form action="login_orion.php" method="post">
						<p>
							Name:				
								<input type="text" name="username"/>
						</p>
						<p>
							Password:				
								<input type="password" name="password"/>
						</p>
						<p>
							<input type="submit" value="Log In"/>
						</p>


				</form>
				</div>	

						<div id="right_column">
							<h1></h1>
							<p>

							</p>
						</div><!--end col 3 div-->
							<div id="estimate_link">
								<a href="estimate.htm">Free Estimate</a>		
							</div>


</div><!--end container div-->

		<div id="copyright">
			© 2008 KDesigns   All Rights Reserved.
		</div>
</body>
</html>

 

When I submit the form online it gives back a completely blank page.

 

You can try it for yourself at:

http://www.kdesigns.net/login_orion.php

 

 

I have called the host and they said they see the sql table in there, and the user info with password.

 

Thanks for looking.

 

 

Link to comment
Share on other sites

GingerRobot - I researched how to turn display errors on, and I have them already turned on in my mac php.ini file, but  how do I do that for the server?  Do I contact my host? I will call them in the mean time.

 

dubc07 - mysql is set up on the db I am just wondering if I am connecting right.

//@ $db = new mysqli( 'mysql.kdesigns.net', 'username', 'password', 'dbname' );

 

I am stumped since I have never before used a db other than from my local machine.

 

 

 

Link to comment
Share on other sites

What do your get when you do a "view source" in your browser of the blank page?

 

Blank pages are usually caused by fatal parse errors, sometimes by fatal runtime errors, and sometimes by code that does not output anything.

 

For the first possibility, nothing you put into the code will help because the code never executes. You need to set the error_reporting and display_errors values in either the master php.ini, a .htaccess file (when php is running as an Apache module), or in a local php.ini (when php is running as a CGI wrapper.)

Link to comment
Share on other sites

Thank you PFMaBiSmAd

 

I set the error reporting by placing

ini_set("display_error","true");
error_reporting(E_ALL);

This is the view source code:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>

 

I am trying to redirect it to another page with a header, I am new to php and programming, so I

don't understand all you wrote.  Can you look at my code at the beginning of this thread and

see if it looks wrong?

 

Thank you.

Link to comment
Share on other sites

display_error should be display_errors and there is a chance that the string "true" does not evaluate to the value TRUE. I personally use the following and know that they work (except for a fatal parse error) -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

What php version is your online server using?

 

Also, there is an @ in front of at least one line of code. Remove any @ in the code being used to suppress errors.

 

 

Link to comment
Share on other sites

PFMaBiSmAd, I finally got an error message.  Thanks!

 

This is it:

Fatal error: Cannot instantiate non-existent class: mysqli in /nfs/cust/4/45/65/556544/web/login_orion.php on line 13

 

I will find out what version of php my host is using tomorrow.

 

I am glad to have progress here. Thank you all for contributing.

 

 

 

 

Link to comment
Share on other sites

The php version is 4.1. 

 

This is the error:

Fatal error: Cannot instantiate non-existent class: mysqli in /nfs/cust/4/45/65/556544/web/login_orion.php on line 13

 

 

This is line 13:

db = new mysqli( 'host', 'username', 'password', 'dbname' );

 

I have tried several different things with line 13 and nothing works.

 

Any suggestions as to what I have wrong here?

 

Thank you all.

 

 

Link to comment
Share on other sites

Thank you Blade280891

 

Now there is a new error:

Fatal error: Call to undefined function: mysqli_connect() in /nfs/cust/4/45/65/556544/web/login_orion.php on line 13

So I will tackle this one.

 

Any suggestions?

 

Seeing these errors does this mean that I am connected to the DB?

Link to comment
Share on other sites

I made that test page as you said and still got this error.

Fatal error: Cannot instantiate non-existent class: mysqli in /nfs/cust/4/45/65/556544/web/test.php on line 2

 

 

Do I have to have different code to connect to php 4.4.1 than php 5?

 

My server is using 4.4.1.

 

What is the deal here, my host said that there is a connection to mysql.

They are not familiar with mysqli however.

 

Going Bonkers.

Link to comment
Share on other sites

I think they are using mysql because one of the techs had never seen the mysqli.

To be honest I don't know the difference.  I have so much great stuff to learn.

I am on hold right now to find out an answer that question, but I think it is the old

version. 

 

I tried the test page you suggested and it still gives the same error just on the new line.  

 

 

At the end of the month the host is upgrading to php5 so maybe I will wait and try again then, unless

we can find the solution

 

Just hope it makes a difference and I can get this login working then.

 

I really appreciate all your time and help here.

 

I am still open to current solutions.

Link to comment
Share on other sites

Yes I have a database on the server, and it connects. 

What doesn't connect is my php pages.

 

Host just told me that it is not mysqli, but mysql 4.1.20

 

So knowing that what is supposed to replace this line?:

$db = new mysqli( 'host', 'username', 'password', 'dbname' );

 

This is the address to my phpini file.

http://www.kdesigns.net/phpinfo.php

 

Thanks people!

 

Link to comment
Share on other sites

Your host doesn't have mysqli installed. your need to update it to mysql

so

<?php
session_start( );

// if username and password are set and not empty then proceed with the rest of the process
if( isset( $_POST[ 'username' ] ) && isset( $_POST[ 'password' ] ) && $_POST[ 'username' ] != '' && $_POST[ 'password' ] != '' )
{
	$username = $_POST['username'];
	$password = $_POST['password']; 

	//@ $db = new mysqli( 'mysql.kdesigns.net', 'username', 'password', 'dbname' );
	@ $db = new mysqli( 'localhost', 'root', 'rn2846', 'kdesignsOrion' );
	//dbet.valueweb.net
	if( mysqli_connect_errno( ) )
	{
		echo"Connection to the database failed. Please try again later." ;			
		exit;
	}

	//checks for username and password in db table.
   	$results = $db->query( "select * from users where username='" . $username . "' and password = '" . $password . "'" );

	//greater than zero		
	if( $results->num_rows > 0 )
	{
		$_SESSION['username'] = $username;  
		//redirect

	}
	else
	{
		echo 'You must be registered before you may log in.';
	}
}
?>

 

will be converted to

<?php
session_start( );

// if username and password are set and not empty then proceed with the rest of the process
if( isset( $_POST[ 'username' ] ) && isset( $_POST[ 'password' ] ) && $_POST[ 'username' ] != '' && $_POST[ 'password' ] != '' )
{
	$username = $_POST['username'];
	$password = $_POST['password']; 

	//@ $db = new mysqli( 'mysql.kdesigns.net', 'username', 'password', 'dbname' );
	$link = mysql_connect('localhost', 'root', 'rn2846');
	//dbet.valueweb.net

$db_selected = mysql_select_db('kdesignsOrion', $link);
if (!$db_selected) {
		echo"Connection to the database failed. Please try again later." ;			
		exit;
}
	//checks for username and password in db table.
$results = mysql_query("select * from users where username='" . $username . "' and password = '" . $password . "'" ,$link);
	$num_rows = mysql_num_rows($result);
	//greater than zero		
	if( $num_rows  > 0 )
	{
		$_SESSION['username'] = $username;  
		//redirect

	}
	else
	{
		echo 'You must be registered before you may log in.';
	}
}
?>

**UNTESTED

 

EDIT: also i would like to add is not very secure SQL injection being the first major problem but lets get it connecting first ;)

Link to comment
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.