delo2795 Posted October 7, 2011 Share Posted October 7, 2011 I'm very new to PhP and one of my asignments in class is to create a simple login using php and mysql. I made a simple page using html, php, and mysql and i keep getting errors. Here is my code so far: This is my index.php page: <html> <form action = 'login.php' method='POST'> Username: <input type='text' name='username'><br> Password: <input type='password' name='password'><br> <input type='submit' value='Log in'> </form> </html> This is my login.php page: <?php $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { &connect = mysql_connect("localhost", "root", " ") or die ("Couldnt connect"); mysql_selct_db("phplogin") or die("Couldn't find db"); } else die ("Please enter a username and password"); ?> mySql file is very basic: 3 columns, id, username, password I dont think my problem is with the mySQL page that was the easiest to make but everytime I hit login in the index.php, the entire script for login.php gets outputted on screen. I would appreciate all the help. Quote Link to comment https://forums.phpfreaks.com/topic/248636-simple-login-script-new-to-php/ Share on other sites More sharing options...
Buddski Posted October 7, 2011 Share Posted October 7, 2011 How are you accessing the php file? (the url in your address bar) Quote Link to comment https://forums.phpfreaks.com/topic/248636-simple-login-script-new-to-php/#findComment-1276857 Share on other sites More sharing options...
delo2795 Posted October 7, 2011 Author Share Posted October 7, 2011 I'm accessing the files through XAMP. Quote Link to comment https://forums.phpfreaks.com/topic/248636-simple-login-script-new-to-php/#findComment-1276866 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 7, 2011 Share Posted October 7, 2011 try this code on your server. create a new .php file and use this code. <?php phpinfo(); ?> run it, do you get anything? Quote Link to comment https://forums.phpfreaks.com/topic/248636-simple-login-script-new-to-php/#findComment-1276873 Share on other sites More sharing options...
delo2795 Posted October 7, 2011 Author Share Posted October 7, 2011 BAH!!! I copied the codes wrong below is what I actually wrote: index.html <html> <form action = 'login.php' method='POST'> Username: <input type='text' name='username'><br> Password: <input type='password' name='password'><br> <input type='submit' value='Log in'> </form> </html> login.php <?php $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect("localhost", "root", "") or die ("Couldnt connect"); mysql_select_db("phplogin") or die("Couldn't find db"); } else die ("Please enter a username and password"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/248636-simple-login-script-new-to-php/#findComment-1276875 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 7, 2011 Share Posted October 7, 2011 try this. maybe it helps. <?php $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect("localhost", "root", "") or die ("Couldnt connect"); mysql_select_db("phplogin") or die("Couldn't find db"); } else { die ("Please enter a username and password"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/248636-simple-login-script-new-to-php/#findComment-1276881 Share on other sites More sharing options...
delo2795 Posted October 7, 2011 Author Share Posted October 7, 2011 I had a file name phpinfo.php set up and I saved it under xamp/htdocs/phpinfo.php. When I first created made the file it ran just fine and now its just repeating whats inside the document meaning <?php phpinfo(); ?> i'm not sure whats going Quote Link to comment https://forums.phpfreaks.com/topic/248636-simple-login-script-new-to-php/#findComment-1276884 Share on other sites More sharing options...
Buddski Posted October 7, 2011 Share Posted October 7, 2011 So to access your HTML/PHP file you ARE in fact going through http://localhost/.....? Quote Link to comment https://forums.phpfreaks.com/topic/248636-simple-login-script-new-to-php/#findComment-1276886 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 7, 2011 Share Posted October 7, 2011 make sure the file is in xamp www or htdocs folder then go to the browser, type http://localhost/ do you get anything? Quote Link to comment https://forums.phpfreaks.com/topic/248636-simple-login-script-new-to-php/#findComment-1276894 Share on other sites More sharing options...
delo2795 Posted October 7, 2011 Author Share Posted October 7, 2011 Ok here is the weird thing. I am using notepad++ and i'm using the run in chrome browser ctrl+alt+shift+r. then it displays my index.php page just find, but when i hit log in it goes to this file:///C:/xampp/htdocs/phpAcademy/tutorials/loginsession/login.php then it just reprints my codes, but if I go to http://localhost//phpAcademy/tutorials/loginsession/index.php everything works just find. I need more practice...with the xampp user interface...well thanks anyways...its solved =P. Quote Link to comment https://forums.phpfreaks.com/topic/248636-simple-login-script-new-to-php/#findComment-1276898 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 7, 2011 Share Posted October 7, 2011 LOL. no prob. kudos to Buddski Quote Link to comment https://forums.phpfreaks.com/topic/248636-simple-login-script-new-to-php/#findComment-1276905 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.