Jump to content

Landslyde

Members
  • Posts

    93
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Landslyde

  1. mac_gyver: Thanks for your response. I'll add the 'exit();' as you suggested. As for my hosting, I'm on a VPS, running Virtualmin for my web site. Options for PHP session tracking Session storage mechanism Files Directory for session files Default (/tmp) /home/dfwit/tmp <== Selected Allow use of cookies for session tracking? Yes Always use cookies for session tracking? Yes Cookie lifetime Forever 5000 seconds // Forever in not selected Maximum session lifetime Forever 5000 seconds // Forever in not selected No one else is on my VPS. What else do I need to look for? Something is making the sessions end prematurely.
  2. the test_input function function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; }
  3. Here's a bit of code from my client login page. It works. <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // First brace if (empty($_POST["uname"])) { $unameErr = "* Username is required"; } else { $uname = test_input($_POST["uname"]); if (!preg_match("/^[a-zA-Z0-9]*$/",$uname)) { $unameErr = "* Letters and numerals only"; } } } // Last brace ?>
  4. I don't know how to fix this. In the php.ini, I have sessions set to auto-start, cookie lifetime and session lifetime both set to 5000 seconds. Thing is, even while I'm doing work (on my site) and have a session started, the session still times out after 15 minutes or so. I've been working on displaying an HTML table with MySQL data all night. I can't count the times that I was sent back to the login page because the session had expired. When the user logs in, I set a session var to their memberID. And on the work pages, I check that each time the page loads: <?php if ($_SESSION["memberid"] == "") { header("Location: client.php"); } ?> I'm new to php, so I'm only guessing the session's expiring due to the memberid session var emptying. Being in the middle of work, having a page load new data, only to be sent back to the login screen time and time again. Does anyone know how I can fix this issue? Many thanks for your time.
  5. Just thought I'd drop my two cents in. I use the same syntax to set my variables to empty. Not only is it legal code, it's clean. // define variables and set to empty values $fnameErr = $lnameErr = $mnameErr = $addressErr = $contactErr = $picErr = $usernameErr = $passwordErr = ""; $fname = $lname = $mname = $address = $contact = $pic = $username = $password = ""; I use it that way in all my code. Even the PHP Cookbook I have shows that. So you're good to go there
  6. Barand: tryingtolearn: You guys are the best! Before I fell asleep at abt 6am, I was wondering if I cld set the value of the option to the ID, to $row[0]. Jumped out of bed just now and see that you guys confirmed that. And also provided examples. Really good forum with class acts here! Thank you both. Much appreciated
  7. I have a db with this therapist's client info. I fixed him a page to view that. I fill a select box's options with the client fname and lname from the MySQL db for him to chose whose details he wants to view. Seemed like a great idea. But now that I have the Select value as a combination of $row[1] and $row[2], I'm at a complete loss as to how to select from the db. I tie the two together like so: <select name="view" style="margin-left: 15px; margin-top: 15px; font-size: 1em;"> <option>All</option> <?php require_once 'login.php'; $stmt = $db->prepare('SELECT * FROM attendees ORDER BY lname'); $stmt->execute(); $result = $stmt->fetchAll(); foreach($result as $row){ ?> <option><?php echo $row[1],' ',$row[2]; ?></option> <?php } ?> </select> Fact is, I'm dead in the water with this. I like the idea of making it convenient for the therapist by giving him this dropdown box, but I have absolutely no idea how to form the Select statement with an option value like John Doe. If I had to I cld remove one of the name fields and simply have him enter first and last names at the same time in one field. But that looks sort of cheesy, you know. Does anyone have any ideas on how to better do this? Ideas are cool...I'll take it from there. I'm not here to get you guys to code for me, just help me with a little thinking, something that's not my best friend right now
  8. I am doing a header() redirect. After the code I posted here, it drops pn down and sends a confirmation email to the user, the it redirects to a thank-you page. Thanks again for you help.
  9. Yes, I use PDO error catching. Kicken is the one who turned me on to how to use PDO's one day. Many thanks for that. See, I use login.php, which has all my login credentials in it: <?php $db = new PDO('mysql:host=localhost;dbname=login', 'root', 'myPW'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); ?> So when I try to create the database from the users username, it shld work. But it doesn't. I may be going about this the wrong way guys. I know that. Maybe all I need is one db and a giant table to handle all the data. And I know I cld keep everything straight between the users by their custID. I'm really new to all this and wasn't thinking that way, but I can see where it wld be a whole lot easier. I think the one thing I don't like is having all the data in a single table. For me, it wld be easier to break things down and make them manageable in multiple tables. However, I think one table with one db is the way to go. I came here for help on one issue and ended up seeing everything in a whole new light. You guys are really good. I listen to you. I might tend to butt heads sometimes, but that's usually how I get convinced, one way or the other. I know most of you do this for a living. Me? I'm just an old man trying to jump in the middle of waters I know nothing of. So thanks to each of you for your input. But before we close this post, can someone please tell me why my code fails to create a db via the users username? While I see that's a bad idea now, I still wld like to know what I'm doing wrong there. Thanks
  10. The top line in my original post is for my login credentials. require_once 'login.php'; // My login credentials try{ $stmt = $db->prepare("CREATE DATABASE IF NOT EXISTS :dbname"); $stmt->bindValue(':dbname', $uname, PDO::PARAM_STR); $stmt->execute(); } catch (PDOException $ex){ echo 'Error creating database: '.$ex; }
  11. Thanks again, CroNiX. The user isn't creating the db. I am (or am trying to). I didn't think to far along on putting all the therapist's client info in one table. I guess that wld work, but it wld sure be a big one. Anyways, please understand that I am the one creating the db and table(s). Not the customer. And I still don't know why my code from my original post up there isn't working. Any help there?
  12. I guess I don't have to create separate db's for the users. I cld instead create the tables to include their names so the data they access is for them and no other. This is for individuals, not a company. The therapist in Washington state will access his/her own data. The one in Florida theirs. So one db wld work, but the tables wld then have to includ their usernames to make them unique to that user. But either scheme shld work for me. Second: I am the one creating the db upon their registration completion. There the user will be assigned priveleges, none of which are create. Hope this helps you understand better what I'm doing. But since I'm new to MySQL, I realize that I may be way off base with my thinking on this, made obvious by the fact that I can't even get the db created
  13. After all the fields have been confirmed on my Registration Form, just before the confirmation email is sent out to the user, I have this code to create a MySQL db from their unique username: require_once 'login.php'; echo $uname; try{ $stmt = $db->prepare("CREATE DATABASE IF NOT EXISTS :dbname"); $stmt->bindValue(':dbname', $uname, PDO::PARAM_STR); $stmt->execute(); } catch (PDOException $ex){ echo 'Error creating database: '.$ex; } My apache error log is clear. Same for MySQL eorror log. No errors reported. I have even commented out the bindValue $stmt and put a name in place of :dbname in the prepare $stmt, but I still get nothing. Anyone see what I'm doing wrong?
  14. I got it. I forgot to set my PHP variable $who with the form value of "who". Has been a long day...time to go to bed now
  15. I have a form set up. One part of that form is a couple radio buttons. The form code for them is: <label for="who" class="label">Email to:</label> <input type="radio" name="who" value="Sales" checked>Sales <input type="radio" name="who" value="Support">Support In my PHP code, I have this to check which one they selected: if($who=="Sales") { $to = "sales@mysite.co"; $subject = "Contact Email"; $headers = "From:" . $email; mail($to,$subject,$msg,$headers); header("Location: mailreceived.html"); } else { $to = "support@mysite.co"; $subject = "Contact Email"; $headers = "From:" . $email; mail($to,$subject,$msg,$headers); header("Location: mailreceived.html"); } But even when I select the Sales radio button, the email is sent to Support. What am I not doing right in my If statement?
  16. I have a form. I have error-catching set up for the form inputs. And in the form, I use the <h3> tage to position a captcha. the bottom part of my form looks like this: <form method="post" class="subform" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>"> ... <p> <label for="pwd2" class="label">Confirm Password:</label> <input type="password" name="pwd2" placeholder="Confirm Password" value="<?php if (isset($_POST['pwd2'])) { echo $pwd2; } ?>"> <span class="error"> <?php echo $pwd2Err;?></span> </p> <?php echo '<h3>'.$funcaptcha->getFunCaptcha("XXXXXXXX-XXXX-6849-XXXXX-XXXXXXXXXXXX").'</h3>'; ?> <input type="submit" value="Register"></button> When an input error occurs, the error text is placed next to the input box. I like that. But I don't know how to setup and display an error next to the captcha if the user fails to complete it. So I've been using $pwd2Err to tell the user it has to be be completed, but using that places the error msg next to the Confirm Password textbox, instead of next to the captcha where it should be. And for all I know, I may be in the wrong forum with this being a CSS issue instead Any ideas how I might get the error message attached to the captcha and display it accordingly?
  17. Very insightful, kicken. I'm just a few days into PHP, but not to programming. I'll study your code and try to learn what I can on the use of PDO in PHP. Although I refined my code: $query = "select username from member WHERE username = '".mysqli_real_escape_string($uname)."'"; // Only selecting the field to compare to $result = $db_conn->query($query); if(!$result) die ('Database access failed: ('.$db_conn->connect_errno.')'.$db_conn->connect_error); $rows = $result->num_rows; $i = 0; if($rows > $i) { $unameErr = "* Username already in use. Please choose another."; mysql_close($db_conn); exit; } to simply check if a row had been returned, the Query is still wrong somehow. I'm still able to create the same username over and over. But what you show me is interesting, cleaner looking. Funny how we want what we want yesterday and today's already too late. Time to slow down and get to know PHP a little better. Thanks for your explanation and code example. It won't go to waste. ~Landslyde
  18. Thanks, Monkuar. I was about to edit my post because I finally woke up and realized that I needed to use WHERE in my Query only to come here and see you had already made the changes. I'm bad about that, getting tunnel vision, not seeing the trees for the forest. Thank you for your time and patience with an old man who obviously didn't drink enough Geritol today! And thanks for the tabbing...looks like a million bucks ~Landslyde
  19. Hello everyone: I'm having trouble with code that compares a Form value ($uname) to Field values (username) from my database. In testing, I'm using the same Form data over and over, and I now have several identical records instead of just one unique record for this user. if (empty($_POST["uname"])) { $unameErr = "* Username is required"; } else { $uname = test_input($_POST["uname"]); if (!preg_match("/^[a-zA-Z0-9]*$/",$uname)) { $unameErr = "* Only letters and numerals are allowed"; } else { // Now sure the username is legit, we check to see if it's a // unique username by comparing it to all usernames already in member table. require_once 'login.php'; // This file contains database access credentials $db_conn = new mysqli($db_hostname, $db_username, $db_password, 'login'); if($db_conn->connect_error) die ('Connect Error: ('.$db_conn->connect_errno.')'.$db_conn->connect_error); $query = "select username from member"; // Only selecting the field to compare to $result = $db_conn->query($query); if(!$result) die ('Database access failed: ('.$db_conn->connect_errno.')'.$db_conn->connect_error); $rows = $result->num_rows; for($i = 0; $i <= $rows; $i++) { if(mysqli_fetch_assoc($result) == $uname) { $unameErr = "* Username already in use. Please choose another."; mysql_close($db_conn); exit; } } $query = "insert into member values(NULL, '$uname', '$pwd1', '$fname', '$lname')"; $result = $db_conn->query($query); if(!$result) die ("Database insertion failed: ".mysql_error()); } } This is my first attempt at this using PHP and am pleased that I can at least access my db. But I just can't figure out how to make this comparison check. Thanks in advance for any help you offer. ~Landslyde
  20. A done deal. Thanks, Monkuar. Oh, I was never getting an error. ginerjm said he was though. Go figure
  21. Like I also said, I don't like to be shouted at. Grow up and stop shouting at people, ginerjm. I took out the echo earlier. And again, thank you for your help. Just stop shouting at me. I'm an adult just like you. You respect me, I'll respect you. But do not shout at me again.
  22. And thank you, ginerjm. Both of you have helped me tremendously. You just can't find this sort of help in the watered-down online tutorials. Many thanks.
  23. Thank you, Monkuar: I appreciate your help. I'll study what you've been so kind to offer me. I'm new at PHP, but I learn fast. But I wonder why I can't see thrown errors? I know that if I have bad syntax in my php that my page won't even load...but I never see the errors. I just have to sift through it and find what I can find.
  24. Yeah, if it wld show me the error (like it seems to do for you), then I'd fix it. I loaded your code and ran it. Still hangs waiting on localhost. But when I uploaded it, it ran like greased lightning. So I will ask you again: is the error suppose to show in the browser? Because I'm getting nothing.
  25. Hmm...I set a couple echo statements prior to the first line in the mail call and one just before the mail() line. But when I submitted the form info, it spun and spun for a minute or so, then it spewed my echoes out and finished in one swift blink of an eye. So whatever is hanging it up is doing so before it reaches the mail call. And I still see no errors. Where will they show? In my browser?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.