Jump to content

xProteuSx

Members
  • Posts

    476
  • Joined

  • Last visited

Everything posted by xProteuSx

  1. Thanks.  That does update the users_lastvisit field.  HOWEVER, it also changes the users_datejoined field to the same value.  How can this be? Here is the code for my CREATE TABLE: [code] $createusertable = " CREATE TABLE users ( users_id int(6) UNSIGNED NOT NULL auto_increment, users_randomkey int(8) UNSIGNED default NULL, users_handle varchar(20) BINARY default NULL, users_password varchar(20) BINARY default NULL, users_email varchar (40) BINARY default NULL, users_adminlevel int(1) UNSIGNED default '0', users_status int(1) UNSIGNED default '0', users_datejoined timestamp NOT NULL, users_visits int (6) UNSIGNED default '0', users_lastvisit timestamp NOT NULL, users_questionsanswered int(6) UNSIGNED default '0', users_correctanswers int(6) UNSIGNED default '0', users_percentcorrect float default '0', users_totalscore int (6) UNSIGNED default '0', users_pagesviewed int(8) UNSIGNED default '0', users_visitbonus int(6) UNSIGNED default '0', users_activity int(6) UNSIGNED default '0', PRIMARY KEY(users_id), UNIQUE(users_handle) ) TYPE=MYISAM; "; [/code] Any ideas?  I have been here before, and I was not able to figure it out.
  2. I have been totally unsuccessful in figuring this out, and I think I have spent enough time, and pulled out enough of my hair, that I can ask for help without any guilt: I have a MySQL DB table called users, and for each entry there are two columns:  users_datejoined and users_lastvisit.  Now, when a user registers, datejoined is set to the time of registration.  Everything works up to this point.  Now, when this user returns to the site and logs in, I would like the users_lastvisit column to be updated.  Upon successful login, the following code should be executed: [code] $sql = "UPDATE users SET users_lastvisit='TIMESTAMP' WHERE users_handle='$mcathandle' AND users_randomkey='$mcatrandomkey'"; $sql_result = mysql_query($sql,$dbh) or die ('The error is as follows: <br><br>' . mysql_error()); [/code] *note that $dbh is the connection string, which does work (I have tested this)! So far, the column users_lastvisit is always at '0000-00-00 00:00:00'.  I cannot seem to change it. What am I doing wrong?  What should the code for the DB UPDATE be?? Thanks in advance.
  3. Fallen_Angel, I could not use a simple link such as <a href="./index2.html">text you want for link </a>.  The reason is a little difficult to explain but I will try ... My first page, page1.php, has a form with some variables.  When you hit Submit you are taken to page2.php which processes the variables from page1.php, and has a form of its own.  When you hit Submit on the second form on page2.php you are taken to page3.php which processes the variables from the form from page2.php.  If there is an error in the variables received by page3.php from the form from page2.php I want a back button on page3.php so that the user can re-enter the info into page2.php.  If, however, I use a simple link what happens is that the browser re-sends for page2.php from the web server, but it does not have the values from page1.php, so there are a series of errors.  If, however, I use the history.back() function of javaScript the page is reloaded from cache, with variables intact. Hope I didn't make anyone dizzy ...
  4. Thanks, I guess I will go with javascript.  Do you know of a similar bit of code where instead of history.back() I could go to another page, such as page2.html?
  5. I remember there used to be a javascript snippet that everyone used to go back one page in browser history.  How do I accomplish this with PHP??  Thanks ...
  6. I am really confused as to how to query a MySQL database.  I have had several examples that work, each somehow different, yet when I try to adapt these examples to new situations, I cannot get them to work.  Really, I am getting frustrated.  Maybe someone can explain this in idiot-proof terms, so that I may be enlightened ... (PLEASE!!!) So here is the sample table named PEOPLE (3 columns (id, username, email, respectively), 5 rows): ID=1  username=Bob  [email protected] ID=2  username=Sue  [email protected] ID=3  username=Joe  [email protected] ID=4  username=Moe  [email protected] ID=5  username=Sam  [email protected] If I want to find the e-mail of the row with ID=2 I would enter the following: [code] $emailquery = "SELECT email FROM `people` WHERE `id` LIKE '2'"; $email_result = mysql_query($emailquery) or die ("The query caused the following error:<br><br>" . mysql_error()); $email_given = mysql_fetch_assoc ($email_result); echo $email_given['users_email']; [/code] This should have the output "[email protected]" right? If I want to find the username of the row with [email protected] I would enter the following: [code] $usernamequery = "SELECT username FROM `people` WHERE `email` LIKE '[email protected]'"; $username_result = mysql_query($usernamequery) or die ("The query caused the following error:<br><br>" . mysql_error()); $username_given = mysql_fetch_assoc ($username_result); echo $username_given['users_username']; [/code] This should have the output "Sam" right? Please, I am stuck and I cannot figure this out ...
  7. I figured it out ... too many quotes ...  It works if I put it in like this: setcookie("randomizer", $randomkey, time()+14400, ".sub.mysite.com", 0);
  8. What the heck does this error mean? "Warning: setcookie() expects parameter 3 to be long" My cookie line look something like this: setcookie("randomizer", "$randomkey", "time()+14400", ".sub.mysite.com");
  9. Thanks zanus!  Now I got 'er up and running again ...
  10. Thanks guys.  I think I have it figured out.  BTW - if you use serialize() you create a security problem (so says php.net; check out their section on cookies).  Right now it seems I am getting ahead of myself. I had my script working just fine, then I switched hosts and now my script won't work at all.  I have the following form: [code] <form method="post" action="index2.php"> <p>Server URL:  <input type="text" name="serverurl" size="30" maxlength="30"></p> <p>Database Name:  <input type="text" name="databasename" size="30" maxlength="30"></p> <p>Database Username:  <input type="text" name="nameofuser" size="30" maxlength="30"></p> <p>Database Password:  <input type="password" name="passofuser" size="30" maxlength="30"></p> <input type="submit" value="Submit"> </form> [/code] The damn thing won't pass the variables to index2.php.  I cannot understand it.  I have been told that variable tracking is turned on at all times on the php version installed on this server, and their documentation states the same.  But I still cannot get the variables to show. I have tried the following (index2.php): [code] echo "$serverurl<br>"; echo "$databasename<br>"; echo "$nameofuser<br>"; echo "$passofuser<br>": [/code] The result are four blank lines.
  11. I am reading a ton of information on cookies, as I am looking to implement a cookie on my website.  However, I cannot find any articles on assigning more than one variable to a cookie.  Everything I read is of the following format: setcookie("name", "value", "expiration", "path", "domain", "security"); So it seems that the cookie can only take one true value field. I am looking to store more than one "value".  For example, if I was looking to store a username, pageviews, and an e-mail address, would I have to set three individual cookies?  This doesn't sound right at all, so I am sure that I am not understanding something.  Any input would be of the greatest assistance ...
  12. Auto generated user keys ... that's a great idea.  I have a few days of other work ahead of me, but I am going to dedicate this upcoming week to sessions and cookies.  Once I get the figured out I think I will have learned enough to complete a rough version of my login script.  Thanks for all the help.
  13. So, roopurt18, what do you suggest?  I would hate to use the IP as part of the cookie/session, because I want to make my site convenient even for those with a dynamic IP.  It seems that you  have come across this dilemma, so I'm wondering if you have a suggestion you could send my way.  I am new to this coding thing, so I am trying to absorb a little knowledge from all sources!  Thanks in advance.
  14. I am a newbie, writing his first script (a login script using MySQL) and I would just like to clarify something, because I have been wrong all too often before.  If I would like to grant a user access to the site based on his or her 'security level' I can use sessions.  But if I would like the user to be able to close his browser and re-open the page again later and still be logged in, that would require a cookie, correct?  So in essence, it would be best to do both, wouldn't it?  Are most programmers using both to accomplish these two tasks simultaneously, or am I missing something?
  15. obsidian, printf, thanks so much for your replies.  Both methods work.  I wish I knew about 'mysql_fetch_assoc' earlier, but my book does not mention this function.  I guess that's what happens when you can only afford a MySQL book written in 2000.  Six years is a long time for something like MySQL ...
  16. I am sending a query to my DB and the output is "Resource #3"  The code is as follows: <?php include ("dbconnect.php"); //connect to the DB $emailquery = "SELECT users_email FROM `users` WHERE `users_handle` LIKE '%Proteus%'"; $email_result = mysql_query($emailquery) or die ("The query caused the following error:<br><br>" . mysql_error()); echo ("$email_result"); ?> What does this mean?  I cannot figure it out ...
  17. fenway, thanks for the reply but I have solved the problem by adding the following code just above the clause which calls for the creation of the table: [code] $sql1 = "DROP TABLE IF EXISTS users"; $result1 = MYSQL_QUERY($sql1); if (!$result1){ print mysql_error(); } [/code] Sadly, I am unsure as to why this worked, but it did.
  18. The following code does not issue an error, but the output is blank: [code] $emailquery = "SELECT users_email FROM users"; $email_result = mysql_query($emailquery) or die ("The query caused the following error:<br><br>" . mysql_error()); $email_result == $email; echo "<p>E-Mail:  $email</p>"; [/code] '$email' must be coming through as blank for some reason, though the field 'users-email' (there is only one row) is populated.
  19. Yeah, the 'users_handle' column is UNIQUE.  Thanks for the tip though.
  20. This is my first day of PHP and MySQL, so please excuse the fact that I still make mistakes or don't know how to throw in an error output clause.  Thanks for the help, though.  My code is now: [code] $emailquery = "SELECT users_email FROM users WHERE users_handle LIKE Proteus"; $email_result = mysql_query($emailquery) or die ("The query " . $emailquery . " caused the following error:<br><br>" . mysql_error()); $email_result = $email; echo "<p>E-Mail:  $email</p>"; [/code] The output for the error is as follows: [code] The query SELECT users_email FROM users WHERE users_handle LIKE Proteus caused the following error: Unknown column 'Proteus' in 'where clause' [/code] Why is the query treating 'Proteus' as a column?  It is an entry in the 'users_handle' column;  this is the same row from which I am trying to output the 'users_email' value. 
  21. I am trying to output the 'users_email' column for user $loginusername from the table 'users'.  The code is below.  The query consistently dies (ie.  Shits its pants).  I don't know what I am doing wrong.  Thanks for the help. [code] $emailquery = "SELECT 'users_email' FROM 'users' WHERE 'users_handle' LIKE '$loginusername'"; $email_result = mysql_query($emailquery) or die ("Query shit its pants!"); $email = $email_result; echo "<p>$email</p>"; [/code]
  22. I have not had a chance to implement the incrementation of the pages viewed variable because I am stuck on something similar: [code] $sqlvisit = "UPDATE `users` SET `users_lastvisit` = NOW( ) WHERE `users`.`users_handle` = '$username' LIMIT 1 ;"; $sql_result = mysql_query($sqlvisit) or die ("<p>Shit didn't work yo!</p>"); [/code] for some reason these two columns in the db are linked: [code] users_datejoined timestamp NOT NULL users_lastvisit timestamp NOT NULL [/code] The database updates, however the columns 'users_lastvisit' and 'users_datejoined' are both updated to the new value of NOW().  Isn't that weird??
  23. I am working on a little login script.  I have it working finally, and am beginning work on starting sessions and registering variables.  I understand how to start a session and set variables, but I have a complex table and need these variables to be imported into MySQL.  Below is a rundown of my table columns: [code] users_id int(6) NOT NULL auto_increment, users_handle varchar(20) default NULL, users_password varchar (20) default NULL, users_email varchar (40) default NULL, users_datejoined timestamp NOT NULL, users_visits int (6) default '0', users_lastvisit timestamp NOT NULL, users_questionsanswered int(6) default '0', users_correctanswers int(6) default '0', users_percentcorrect float default '0', users_totalscore int (6) default '0', users_pagesviewed int(8) default '0', users_visitbonus int(6) default '0', users_activity int(6) default '0', [/code] As you can see, there are quite a few variables to be tracked.  But lets work with one for now.  Third from last is 'users_pagesviewed'.  How do I get the database to increment that value by 1 every time the visitor views a page on my website?  I don't even know where to start. zanus ... I know you're around somewhere ...  ;D
  24. Well, I am unsure why this works, but it does. [code] include ("dbconnect.php"); $sql1 = "DROP TABLE users"; $result1 = MYSQL_QUERY($sql1); if (!$result1){ print mysql_error(); } $sql = " CREATE TABLE users ( users_id int(6) NOT NULL auto_increment, users_handle varchar(20) default NULL, users_password varchar (20) default NULL, users_email varchar (40) default NULL, users_datejoined timestamp NOT NULL, users_visits int (6) default '0', users_lastvisit timestamp NOT NULL, users_questionsanswered int(6) default '0', users_correctanswers int(6) default '0', users_percentcorrect float default '0', users_totalscore int (6) default '0', users_pagesviewed int(8) default '0', users_visitbonus int(6) default '0', users_activity int(6) default '0', PRIMARY KEY(users_id), UNIQUE(users_handle) ) TYPE=MYISAM; "; $result = MYSQL_QUERY($sql); if (!$result){ print mysql_error(); exit; [/code] I don't like making things work and then keep going without first understanding why they worked.  For some reason if I dropped the table as a separate entity everything works out.  Again, I think this has something to do with the whole $sql variable, which I am hazy on.  I just made another, $sql1, and did things that way.  Querky ... On another note, Zanus, thank you VERY MUCH for your help.  Please do not lose patience with me.  I have 3 text books in front of me and 4 tutorials opened up on my desktop.  I'm not trying to make anyone write the code for me.  Really, I am trying to learn.  The help I get at PHPFreaks accelerates my learning process.  What an awesome community!
  25. So if I don't assign a connection variable to the connection string, what two arguments do I use for the function mysql_select_db?  The first will be the database name, but what about the other?  Or does the function only require one variable?
×
×
  • 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.