Jump to content

LittleJoe

Members
  • Posts

    35
  • Joined

  • Last visited

Everything posted by LittleJoe

  1. LittleJoe

    Multisite login

    If I have a website, say example.com, and I use PHP sessions to store the login details, can I then access the same session from my.example.com and another.example.com? I need a website with subdomains that have different purposes but the user should only have to log in once at the root domain.
  2. In application programming it's often best practise if not necessary to declare variables at the start of functions instead of just anywhere inside the function when first used. Does this make any difference in PHP? function MyFunction(){$myVariable; // A lot of code $myVariable = OtherFunction();} VERSUS function MyFunction(){// A lot of code $myVariable = OtherFunction();}
  3. That actually makes sense. Thanks.
  4. LittleJoe

    header location

    I have a pretty long script with two header functions which make use of the HTTP location thing. So basically, if a certain criteria is met then the first one is fired otherwise the script is supposed to continue until it gets to the second one. However, the script always seems to jump over the first one and not stop there but to continue until it reaches the second one. Example: if ($somethingIsTrue){ header("Location: first.php");} // a whole lot of code header("Location: second.php"); The only way to get it to stop at the first one is to do this: if ($somethingIsTrue){ header("Location: first.php"); exit;} // a whole lot of code header("Location: second.php"); Otherwise it just runs over the first one. Is this normal? Is there something that I'm missing?
  5. Thank you so much that worked just great. What had me confused was that when I use affected_rows it works on $connection and not $result so that seems to be opposite to how things work with num_rows.
  6. I'm using object-oriented MySQLi prepared statements and I'm getting the hang of it but there's something I don't quite understand. When I use INSERT, UPDATE, REPLACE and DELETE I can use affected_rows to know if I was successful, that the query actually did something. However, when I want to see if anything was returned by my SELECT statement I turn to num_rows in hope that I can see how many rows were returned before I try to use the result as an array. The problem I have is I always get the following: Notice: Undefined property: mysqli::$num_rows in C:\UniServer\www\website\index.php on line 60 So, should I be using num_rows or something different? How do you guys recommend that I first check to see if the result variable has received something before I try to use it as an object? Here's some code that shows what I've been doing: <?php $connection = new mysqli("localhost", "root", "password", "website_database"); $result = $connection->prepare("SELECT * FROM `users` WHERE email = ? AND password = ? LIMIT 1"); $result->bind_param("ss", $email, $password); $result->execute(); if ($connection->num_rows > 0) { // Do something meaningful if there was actually a row returned, otherwise don't do anything. // I don't want to just go straight to using result with "$row = $result->fetch_row();" // because I don't even know if there was a user with that email and password.} ?>
  7. So basically, you have to go through the submit buttons and see if they're set and then look for the input field named "email".
  8. So how do you go about figuring out which form was submitted when multiple ones have fields with the same name such as in this example: <form action="index.php" id="login" method="post"><input name="email" type="text"><input name="loginSubmit" type="submit"></form> <form action="index.php" id="register" method="post"><input name="email" type="text"><input name="registerSubmit" type="submit"></form> Both forms have an input named "email".
  9. Yes, I know. I'm not talking about the name attribute in general but when used in the form tag: <form name="formname"></form> Another related question; if you have multiple forms and some of the input fields in the various forms have the same name, how can you filter input fields or other form fields by a specific form? Can you do in PHP for example: "give me the field where name is "email" in the form where name is "loginform"?
  10. I'm wondering whether the name attribute has any purpose in the form tag because when I see PHP scripts working out which form was submitted to a page, in cases where a page has multiple forms and they all submit to the same page, they always just look for the submit button using the name attribute to realise which form it was that submitted to the page. So when would you want to look for the name on the form tag itself? I ran some tests in a PHP script and I was always able to tell which form submitted to my page looking for the submit button but the name attribute on the form tag itself was always empty. Another related question; if you have multiple forms and some of the input fields in the various forms have the same name, how can you filter input fields or other form fields by a specific form? Can you do in PHP for example: "give me the field where name is "email" in the form where name is "loginform"? Thanks.
×
×
  • Create New...