-
Posts
37 -
Joined
-
Last visited
Everything posted by lewashby
-
I have a script that gets it's values via $_POST and then jumps to another script via the header() function, so I need to somehow pass the variables from the first script to the one that the header function jumps to. I think I need to take a look into sessions.
-
I've scooped up the variables via $_POST from and html from and now they're available in my current php script/file. But what if I wanted to send those values to another php script that will not have the luxury using $_POST to gather the html form variables since the form points to the script that executed/called the current script, not the current script it's self. Any ideas on how I can accomplish this? Thanks.
-
But I need the lines to stop after a match is found. I breaks are only there when a match is found to keep the loop from continuing after I have my banana.
-
In the following program I need to step through a text file line by line checking to see if an email address and then a password are present. It currently works for the first entry in the accounts.txt file but fails if I try the second entry in the form. Any ideas? <?php $email = $_POST['email']; $psswd = $_POST['psswd']; $db = new SQLite3('./users.db', SQLITE3_OPEN_READWRITE); if(!$db) { echo "Could not open/access DB"; } else { $result = $db->query("SELECT email, password FROM users WHERE email='$email'"); $user = $result->fetchArray(); if(!$user) { $file = fopen("./accounts.txt", 'r+') or die("Failed to open file"); while(!feof($file)) { $line = fgets($file); if(strpos($line, "$email") !== false) { if(strpos($line, "$psswd") !== false) { header("location: ./changepassword.html"); break; } else { echo "Invalid password"; break; } } else { echo "Invalid email address"; break; } } fclose($file); } else { if($psswd == $user['password']) { echo "You have already changed your password"; } } } ?>
-
Psycho - thanks that got it. This has been killing me for about two weeks.
-
Psycho - Thanks, I just tried it bit it still doesn't seem to be working. Does this line "if(!$user)" check to see if $user holds a 'false' value? The documentation says that the function will return false if there are no more rows, not if there is no match. <?php $email = $_POST['email']; $psswd = $_POST['psswd']; $db = new SQLite3('./users.db', SQLITE3_OPEN_READWRITE); if(!$db) { echo "Could not open/access DB"; } else { //$userEmail = $db->query("SELECT email FROM users WHERE email='$email'"); //$userPsswd = $db->query("SELECT password FROM users WHERE email='$email'"); $result = $db->query("SELECT email, password FROM users WHERE email='$email'"); $user = $result->fetchArray(); if(!$user) { echo 'No user match in database'; } //if($email == $userEmail && $psswd == $userPsswd) elseif($psswd == $user->password) { echo "You have already changed your password"; } else { $file = fopen("./accounts.txt", 'r+') or die("Failed to open file"); while(!feof($file)) { $line = fgets($file); if(strpos($line, "$email") !== false) { echo "User was a match"; if(strpos($line, "$psswd") !== false) { header("location: ./changepassword.html"); break; } else { echo "Invalid password"; break; } } else { echo "Invalid email address"; break; } } } fclose($file); } ?> PHP Notice: Trying to get property of non-object in /var/www/ET/password/accounts.php on line 28
-
Psycho - Thanks, I just tried it bit it still doesn't seem to be working. Does this line "if(!$user)" check to see if $user holds a 'false' value? The documentation says that the function will return false if there are no more rows, not if there is no match. <?php $email = $_POST['email']; $psswd = $_POST['psswd']; $db = new SQLite3('./users.db', SQLITE3_OPEN_READWRITE); if(!$db) { echo "Could not open/access DB"; } else { //$userEmail = $db->query("SELECT email FROM users WHERE email='$email'"); //$userPsswd = $db->query("SELECT password FROM users WHERE email='$email'"); $result = $db->query("SELECT email, password FROM users WHERE email='$email'"); $user = $result->fetchArray(); if(!$user) { echo 'No user match in database'; } //if($email == $userEmail && $psswd == $userPsswd) elseif($psswd == $user->password) { echo "You have already changed your password"; } else { $file = fopen("./accounts.txt", 'r+') or die("Failed to open file"); while(!feof($file)) { $line = fgets($file); if(strpos($line, "$email") !== false) { echo "User was a match"; if(strpos($line, "$psswd") !== false) { header("location: ./changepassword.html"); break; } else { echo "Invalid password"; break; } } else { echo "Invalid email address"; break; } } } fclose($file); } ?>
-
Here's where I'm at now. <?php $email = $_POST['email']; $psswd = $_POST['psswd']; $db = new SQLite3('./users.db', SQLITE3_OPEN_READWRITE); if(!$db) { echo "Could not open/access DB"; } else { //$userEmail = $db->query("SELECT email FROM users WHERE email='$email'"); //$userPsswd = $db->query("SELECT password FROM users WHERE email='$email'"); $row1 = $db->query("SELECT email FROM users WHERE email='$email'"); $row2 = $db->query("SELECT password FROM users WHERE email='$email'"); $userEmail = $row1->fetchArray(); $userPsswd = $row2->fetchArray(); if($email == $userEmail && $psswd == $userPsswd) { echo "You have already changed your password"; } else { $file = fopen("./accounts.txt", 'r+') or die("Failed to open file"); while(!feof($file)) { $line = fgets($file); if(strpos($line, "$email") !== false) { echo "User was a match"; if(strpos($line, "$psswd") !== false) { header("location: ./changepassword.html"); break; } else { echo "Invalid password"; break; } } else { echo "Invalid email address"; break; } } } fclose($file); } ?>
-
I have also tried the fetch array method. The page displays but still adds an error entry to /var/log/apache2/error.log when I include the SQLITE_NUM option and also display but give no error when I leave that option out. Either way the code to check against that string is still being skipped.
-
Is that not exactly what I did? It looks like you just copied two have my own lines and pated them here. What am I missing? Thanks.
-
In the following program can someone please tell me why my script is skipping the first else clause and never printing "You have already changed your password"? Everything else is working fine but when I enter in a username and password that have already been entered into the system it skips the portiong of code designed for that case. Thanks. <?php $email = $_POST['email']; $psswd = $_POST['psswd']; $db = new SQLite3('./users.db', SQLITE3_OPEN_READWRITE); if(!$db) { echo "Could not open/access DB"; } else { $userEmail = $db->query("SELECT email FROM users WHERE email='$email'"); $userPsswd = $db->query("SELECT password FROM users WHERE email='$email'"); if($email == $userEmail && $psswd == $userPsswd) { echo "You have already changed your password"; } else { $file = fopen("./accounts.txt", 'r+') or die("Failed to open file"); while(!feof($file)) { $line = fgets($file); if(strpos($line, "$email") !== false) { echo "User was a match"; if(strpos($line, "$psswd") !== false) { header("location: /ET/password/changepassword.html"); break; } else { echo "Invalid password"; break; } } else { echo "Invalid email address"; break; } } } fclose($file); } ?>