rnintulsa Posted July 17, 2008 Share Posted July 17, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/ Share on other sites More sharing options...
dubc07 Posted July 17, 2008 Share Posted July 17, 2008 make sure you have mysql setup . Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-592795 Share on other sites More sharing options...
GingerRobot Posted July 17, 2008 Share Posted July 17, 2008 A blank page is usually caused because there's an error, but you have display_errors turned off. See if you can either enable this option, or check your error log. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-592802 Share on other sites More sharing options...
rnintulsa Posted July 18, 2008 Author Share Posted July 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-592936 Share on other sites More sharing options...
unkwntech Posted July 18, 2008 Share Posted July 18, 2008 At the top of the script place: <?php ini_set("display_error","true"); error_reporting(E_ALL); This will set error reporting to ALL for this file. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-592941 Share on other sites More sharing options...
rnintulsa Posted July 18, 2008 Author Share Posted July 18, 2008 unkwntech- Thank you, I added the error code, but I am still getting the blank page when I try logging in from the website. Yet it is still working on my local machine when I login from there. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-592964 Share on other sites More sharing options...
PFMaBiSmAd Posted July 18, 2008 Share Posted July 18, 2008 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.) Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-592969 Share on other sites More sharing options...
rnintulsa Posted July 18, 2008 Author Share Posted July 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-592976 Share on other sites More sharing options...
PFMaBiSmAd Posted July 18, 2008 Share Posted July 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-592997 Share on other sites More sharing options...
rnintulsa Posted July 18, 2008 Author Share Posted July 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-593023 Share on other sites More sharing options...
rnintulsa Posted July 21, 2008 Author Share Posted July 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595551 Share on other sites More sharing options...
rnintulsa Posted July 21, 2008 Author Share Posted July 21, 2008 Learning more here. My host set me up with my phpini file. So I guess I can edit it now. Is the answer to my problem? Here is the current ini http://www.kdesigns.net/phpinfo.php Progress for this newbie! Thanks all. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595615 Share on other sites More sharing options...
rnintulsa Posted July 21, 2008 Author Share Posted July 21, 2008 On the phone my host told me we were using php 4.1, but in looking at the phpini file I see it is 4.4.1 if that makes a difference. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595624 Share on other sites More sharing options...
DeanWhitehouse Posted July 21, 2008 Share Posted July 21, 2008 should this $db = new mysqli( 'localhost', 'root', 'rn2846', 'kdesignsOrion' ); not be $db = mysqli_connect( 'localhost', 'root', 'rn2846', 'kdesignsOrion' );//or something similar? Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595627 Share on other sites More sharing options...
rnintulsa Posted July 21, 2008 Author Share Posted July 21, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595648 Share on other sites More sharing options...
DeanWhitehouse Posted July 21, 2008 Share Posted July 21, 2008 im not sure it shouldnt http://php.oregonstate.edu/manual/en/mysqli.connect.php maybe try putting the connection under the session_start(); instead of in the statement Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595654 Share on other sites More sharing options...
rnintulsa Posted July 21, 2008 Author Share Posted July 21, 2008 My host is running 4.4.1 and I can't connect using : $db = new mysqli( 'host', 'username', 'password', 'dbname' ); Should this line be different? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595789 Share on other sites More sharing options...
DeanWhitehouse Posted July 21, 2008 Share Posted July 21, 2008 try just doing new mysqli( 'host', 'username', 'password', 'dbname' ) or die("error"); on a blank page , so it would be like <?php new mysqli( 'host', 'username', 'password', 'dbname' ) or die("error"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595803 Share on other sites More sharing options...
rnintulsa Posted July 21, 2008 Author Share Posted July 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595975 Share on other sites More sharing options...
DeanWhitehouse Posted July 21, 2008 Share Posted July 21, 2008 Are you using a mysql database or mysqli? Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595984 Share on other sites More sharing options...
rnintulsa Posted July 21, 2008 Author Share Posted July 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595989 Share on other sites More sharing options...
DeanWhitehouse Posted July 21, 2008 Share Posted July 21, 2008 do you even have a database created on the server? Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595996 Share on other sites More sharing options...
MadTechie Posted July 21, 2008 Share Posted July 21, 2008 mysqli connect to mysql, but the it must be enabled create a test page <?php phpinfo(); ?> open it and search for mysqli if you don't see it use mysql instead Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-595999 Share on other sites More sharing options...
rnintulsa Posted July 21, 2008 Author Share Posted July 21, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-596005 Share on other sites More sharing options...
MadTechie Posted July 21, 2008 Share Posted July 21, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/115300-solved-login-problem/#findComment-596012 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.