mancombe Posted October 10, 2009 Share Posted October 10, 2009 hello im new to php and i tried to write a login script but when i run it i get code on my page so i must have made a mistake either missed something a tag or such mayb a morecitical error either way its anoying and i cant find it <?php mysql_connect("myhost here", "myuser", "mypass") or die(mysql_error()); mysql_select_db("db0819443") or die(mysql_error()); if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM members WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: members.php"); } } } if (isset($_POST['submit'])) { if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM members WHERE username = '".$_POST['username']."'")or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database.'); <a href=register.php>Click Here to Register</a> } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location: members.php"); } } } ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <p> any help would be cool Quote Link to comment Share on other sites More sharing options...
TheJoey Posted October 10, 2009 Share Posted October 10, 2009 put your code in tags makes it easier to read Quote Link to comment Share on other sites More sharing options...
cags Posted October 10, 2009 Share Posted October 10, 2009 How are you attempting to run the file? Does it have a file extenion of PHP? Are you running it locally? If so do you have a server setup which supports PHP (such ie WAMP, XAMPP, LAMP etc.)? Are you placing the file in the RootDirectory of your server and accessing it in your browser using http://localhost/folder_name? Quote Link to comment Share on other sites More sharing options...
Stephen68 Posted October 10, 2009 Share Posted October 10, 2009 can't really see anything that would make your code show up in the browser, did you save the page with .php extension ? Quote Link to comment Share on other sites More sharing options...
mancombe Posted October 10, 2009 Author Share Posted October 10, 2009 can't really see anything that would make your code show up in the browser, did you save the page with .php extension ? yeah its saved as index.php it was login.php but i had to rename it index because it would not show whn i uploaded it. What i see is the uernam and password box but above that it shows a lot of the php code i think the error is some place by the link they click if the are not a member click here to register. Quite anoying really :/ but thanks for taking a look Quote Link to comment Share on other sites More sharing options...
mancombe Posted October 10, 2009 Author Share Posted October 10, 2009 How are you attempting to run the file? Does it have a file extenion of PHP? Are you running it locally? If so do you have a server setup which supports PHP (such ie WAMP, XAMPP, LAMP etc.)? Are you placing the file in the RootDirectory of your server and accessing it in your browser using http://localhost/folder_name? yeah im uploading it to the rootDirectory on my univercity account and to view the pages i have to type the exact url such as www.my-linux/studentnumber Quote Link to comment Share on other sites More sharing options...
cags Posted October 10, 2009 Share Posted October 10, 2009 It will display the code if the server doesn't know to parse it, does your university account actually support PHP? Quote Link to comment Share on other sites More sharing options...
mancombe Posted October 10, 2009 Author Share Posted October 10, 2009 It will display the code if the server doesn't know to parse it, does your university account actually support PHP? i should hope so its a php module yeah it does lol thats the server they set up for me to upload it if you rename the register.php index.php it lets them register but its just the login page shows "some" of the code :/ Quote Link to comment Share on other sites More sharing options...
cags Posted October 10, 2009 Share Posted October 10, 2009 You say 'some' of the code, which bits? If you used short code tags, theres a fair chance the server doesn't support it. So if you used... <? echo "something"; ?> // the output may be '<? echo "something"; ?>' // whereas this <?php echo "something"; ?> // the output would be 'something'; Quote Link to comment Share on other sites More sharing options...
mancombe Posted October 10, 2009 Author Share Posted October 10, 2009 You say 'some' of the code, which bits? If you used short code tags, theres a fair chance the server doesn't support it. So if you used... <? echo "something"; ?> // the output may be '<? echo "something"; ?>' // whereas this <?php echo "something"; ?> // the output would be 'something'; the part of code that shows on the pages start at where i have Click Here to Register and it goes all the way down to header("Location: members.php"); Quote Link to comment Share on other sites More sharing options...
cags Posted October 10, 2009 Share Posted October 10, 2009 If you'd have mentioned that to start with.... You have... <a href=register.php>Click Here to Register</a> ... written in the middle of a block of php which is invalid. Any HTML directly inside a php block (ie <?php ?>) should either be part of an echo/print statement. You cannot just write html code inside PHP. Also the location you've put it in doesn't seem valid since as soon as you call die() on the line before hand the script will stop running. Quote Link to comment Share on other sites More sharing options...
mancombe Posted October 10, 2009 Author Share Posted October 10, 2009 If you'd have mentioned that to start with.... You have... <a href=register.php>Click Here to Register</a> ... written in the middle of a block of php which is invalid. Any HTML directly inside a php block (ie <?php ?>) should either be part of an echo/print statement. You cannot just write html code inside PHP. Also the location you've put it in doesn't seem valid since as soon as you call die() on the line before hand the script will stop running. Thanks you very much you was quite correct moved this tag outside the php script and i no longer have the script showing on my screen Quote Link to comment 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.