wildbuddha Posted June 24, 2013 Share Posted June 24, 2013 function login() { $db_hostname = "localhost"; $db_username = "root"; $db_password = ""; $db_name = "justinalba_module3_db"; $dbc = @mysqli_connect($db_hostname, $db_username, $db_password, $db_name) or die("Unable to connect to MySQL"); if (isset($_POST['submitLogin'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['userName'] | !$_POST['passwordLogin']) { die('You did not fill in a required field.'); } $query = mysqli_query($dbc,"SELECT * FROM user WHERE name_username = '".$_POST['userName']."'") or die(); //Gives error if user dosen't exist $check = mysqli_num_rows($query); if ($check == 0) { die('That user does not exist in our database. <a href=registration.php>Click Here to Register</a>'); } while($info = mysqli_fetch_array( $query )) { $_POST['passwordLogin'] = stripslashes($_POST['passwordLogin']); $info['password'] = stripslashes($info['password']); //gives error if the password is wrong if (md5($_POST['passwordLogin']) != $info['password']) { die('Incorrect password, please try again.'); } else { $myFile = "test.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); $stringData = $_POST['userName']."\n"; fwrite($fh, $stringData); fclose($fh); session_start(); $_SESSION['username'] = $_POST['userName']; header ("Location: profile.php"); } } } } I'm having a problem with the above code where the file writing isn't writing to the file at all. Any suggestions? Thanks, in advance, for any help. Quote Link to comment https://forums.phpfreaks.com/topic/279495-login-not-appending-to-txt-file/ Share on other sites More sharing options...
DaveyK Posted June 24, 2013 Share Posted June 24, 2013 You can always do a var_dump() on fwrite to see what fwrite is returning. var_dump(fwrite($fh, $stringData)); Quote Link to comment https://forums.phpfreaks.com/topic/279495-login-not-appending-to-txt-file/#findComment-1437598 Share on other sites More sharing options...
ginerjm Posted June 24, 2013 Share Posted June 24, 2013 Your comment says that your query statement gives error if it fails. But you don't show an error message with simply 'or die()'. Try adding some text to the die and see if it says something. Then add some other echos in the following code to check your progress so you can see how far you are getting and debug your problem. Also - turn on error checking. It will help you debug some other errors. For ex., you have an if statement at the top with a '|' in it, which is not a proper logical connector. ('OR' is usually '||') Quote Link to comment https://forums.phpfreaks.com/topic/279495-login-not-appending-to-txt-file/#findComment-1437642 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.