Jump to content

trq

Staff Alumni
  • Posts

    30,999
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by trq

  1. I'm sorry but this absolutely wreaks of poor design and isn't what I would call OOP at all. Hence, you are at this problem. Why not design well in the first place using best practices and design patterns?
  2. Sorry, I didn't realize you where such a sensitive soul. And now to pick on AlexWD's code. This entire section: if($row['password'] == $_POST['password'] && $row['username'] == $_POST['username']) isn't needed, because we know the username & password matched, or we would have already found out because we would have had mysql_num_rows() return 0. If I where to write the OP's code, it would be something like: <?php session_start(); if (!isset($_SESSION['user'])) { if (isset($_POST['username'], $_POST['password']) { mysql_connect('', '', ''); mysql_select_db(''); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $sql = "SELECT username, password FROM users WHERE username='$username' AND password='$password' LIMIT 1"; if ($result = mysql_query($result)) { if (mysql_num_rows($result)) { // user is valid, log in. $_SESSION['user'] = $_POST['username']; // redirect to somewhere useful. } else { echo "Sorry, the username or password is incorrect. <a href='index.php'>Back</a>"; } } else { // Query failed. We have a problem. trigger_error(mysql_error() . "<br />$sql"); echo "Sorry, there was a problem logging you in, try again later"; } } else { echo "You must fill out all the fields before going any further."; echo "<br/><br/><center><form action='index.php' method='POST'>Username: <input type='text' name='username'>"; echo "<br/>Password: <input type='text' name='password'><br/><input type='submit'></form></center>"; } } else { echo "You are already logged in"; }
  3. First line: Assign 0 (false) to $forever because (0 != 1) equates to true. Second line: if $forever equals true (it doesn't, it equals false) do nothing, else if $forever equals false (which it does), still do nothing. In other words, this line does nothing. Third line: While $forever equals true (which it doesn't) echo "all your base are belong to us\n" In other words, these three lines of code do pretty much nothing.
  4. This part.... if($row_cue['username'] <= 1) will be true if the user does or doesn't exist. Thats as far as I went. Your code however is all over the place and needs to be completely rewritten. Why are you executing a query on the same table 3 different times?
  5. Nothing in your code updates anything. The snippet in your last reply simply assigns values from the database columns, to there own respective variables. This.... while ($row = mysql_fetch_assoc($result)) { extract($row); } Does exactly the same thing.
  6. This idea wreaks of poor design and is precisely the opposite way around to how things should be done. You should be storing the value of your invoice_id within your database and then simply replacing the #{$invoice_id) text within your template with that value. If you still wish to go down the path you are on, take a look at eval, generally though, if you need to use eval your design is incorrect.
  7. Actually, I see you might actually want the loop after all. Just seems odd creating multiple forms but anyway.... <?php if (isset($_GET['id'])) { mysql_connect("mysql.xxx.com", "usre", "pass") or die('Unable to connect to database' .mysql_error()); mysql_select_db("contactsfind"); $id = mysql_real_escape_string($_GET['id']); $query = "SELECT * FROM contacts WHERE id='$id'"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { extract($row); // form goes here. } } else { // no results found, handle error } } else { // query failed, handle error } } else { // id not set, handle error } ?>
  8. Your code is terrible. Never use short open tags, always check your queries succeed before using there result, make sure variables are set before executing code that relies on them, always sanitize data coming from outside & why loop when your only expecting one row? <?php if (isset($_GET['id'])) { mysql_connect("mysql.xxx.com", "usre", "pass") or die('Unable to connect to database' .mysql_error()); mysql_select_db("contactsfind"); $id = mysql_real_escape_string($_GET['id']); $query = "SELECT * FROM contacts WHERE id='$id' LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); extract($row); // form goes here. } else { // no results found, handle error } } else { // query failed, handle error } } else { // id not set, handle error } ?>
  9. I'm not though. Just spending my time learning more useful ones.
  10. 1. In a web page, along with your form and button called 'here'. 2. Push the button. 3. Apache is a web server. You need a web server to be able to make web pages with php.
  11. That should do it providing the correct permissions are set. remember the script will execute as your Apache user.
  12. Post your relevant problematic code and a description of your actual problem.
  13. trq

    User Levels

    This post is on the right track. The link that Zanus provides within that thread will also be very helpfull.
  14. I'm not sure what this would have to do with Apache. We need to see the script, and your crontab entry. Have you checked cron's logs?
  15. I doubt site like Facebook, Google or Yahoo have web based administration interfaces, but anyway.... I generally make admin areas a subdomain. eg; http://admin.domainname.com
  16. Please visit the phpSHIELD php encoder site to download required loader.
  17. You'll want to do neither, and look into using sql joins.
  18. I'm pretty sure xampp installs php as an Apache module. It needs to be installed as cgi to do what your after.
×
×
  • 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.