Jump to content

unsider

Members
  • Posts

    610
  • Joined

  • Last visited

    Never

Everything posted by unsider

  1. That's a good point actually, I think I'll look into sessions, and only allow the user to post every so many minutes/seconds.
  2. This bit of code, allows the user to input the information into the DB, then it outputs what they have added. When the page is reloaded, the data is then displayed a second time. I've discovered if you add a question mark to the end before the reload it does not resend the form again. http://example.com/index.php? if (!@mysql_select_db("//working database")) { echo 'Unable to locate the ' . 'database.'; } if(isset($_POST['commenttext'])) { $commenttext = $_POST['commenttext']; $name = $_POST['name']; $email = $_POST['email']; $sql = "INSERT INTO comments SET commenttext ='$commenttext', commentdate =NOW(), name ='$name', email='$email'"; if (!@mysql_query($sql)) { echo 'Error adding query: ' . mysql_error(); } } echo 'The comments listed in the database...<br>'; $result = @mysql_query('SELECT commenttext, commentdate, name, email FROM comments'); if (!$result) { echo 'Error performing query: ' . mysql_error(); } echo '<table>'; $tr=1; while ($row = mysql_fetch_array($result)) { echo '<tr class="tr' . $tr . '"><td>' . $row["name"] . ' says: <br>' . $row['commentdate'] . '<br>' . $row['commenttext'] . '</td></tr>'; if($tr==1){ $tr=2; } else if($tr==2){ $tr=1; } } echo '</table>'; echo '<br>'; echo '<a href="' . $_SERVER['PHP_SELF'] . '?addcomment=1">Add comment!</a>';
  3. I am running Safari on OS X, and I have designed a simple little comment page, with the basic variables, $date, $text, $session_username, etc... Well when the page is reloaded, the form is submitted twice, and this is the problem. How would I go about fixing this error, so that the user an reload the page without the form being submitted twice? If you needs samples of my code, just let me know.
  4. I know it takes time, but I'd really appreciate the help. I need it.
  5. When I tried to change it to the functionality I wanted I ended up having problems trying to redirect back to the index.php without any errors. I wish I would have saved some of the errors, but basically it did not follow the path I would have liked. I'm just seeing if I need to clarify more things, do you know what I'm trying to accomplish?
  6. register.php (register with forms, no problem inputing into DB), if successful redirect to: index.php (contains log in forms, enter info, action="login.php") login.php(process the information, and if successful redirect back to index.php) With a message displaying you are logged in, giving you the option to log out. (logout is pressed, redirected to logout.php) logout.php then once destroying redirects once again to index.php with everything cleared displaying you are no longer logged in. That's my problem, thats what I'm attempting to do. Sorry if I wasn't clear enough, hard to ask a question when the scripts work, but not the way i want them too
  7. I changed back to the scripts that functioned propery. registration->login->index->logout->login but unfortunately that's not what i wanted, and im not sure how to change it to function properly.
  8. Ok, I have been attempting to do a pretty simple task for the last little while, and unfortunately I've failed miserably. I am trying to: Establish the main section of website: index.php I need a registration page: register.php I need a login script that process my login info: login.php I need a script that destroys existinging mess: logout.php register.php (register with forms, no problem inputing into DB), if successful redirect to: index.php (contains log in forms, enter info, action="login.php") login.php(process the information, and if successful redirect back to index.php) With a message displaying you are logged in, giving you the option to log out. (logout is pressed, redirected to logout.php) logout.php then once destroying redirects once again to index.php with everything cleared displaying you are no longer logged in. I have tried, but I've failed, here are the scripts I've been using, please feel free to edit so they are efficent, and work correctly. Note: database contains: id, username, password, email. The include file is the db connect, so don't worry about any of that. If you have the time to help a poor soul out, I'd much appreciate it. Thanks. index.php <title>rhythmic design</title><?php session_start(); if (!$_SESSION["valid_user"]) { Header("Location: login.php"); } echo "<p>User ID: " . $_SESSION["valid_id"]; echo "<p>Username: " . $_SESSION["valid_user"]; echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]); echo "<p><a href=\"logout.php\">Click here to logout!</a></p>"; ?> register.php <?php include ("db_connect.inc.php"); if ( $_GET["op"] == "reg" ) { $bInputFlag = false; foreach ( $_POST as $field ) { if ($field == "") { $bInputFlag = false; } else { $bInputFlag = true; } } if ($bInputFlag == false) { die( "Problem with your registration info. " ."Please go back and try again."); } $q = "INSERT INTO `members` (`username`,`password`,`email`) " ."VALUES ('".$_POST["username"]."', " ."PASSWORD('".$_POST["password"]."'), " ."'".$_POST["email"]."')"; $r = mysql_query($q); if ( !mysql_insert_id() ) { die("Error: User not added to database."); } else { Header("Location: index.php"); } } elseif ( $_GET["op"] == "thanks" ) { echo "<h2>Thanks for registering!</h2>"; } else { echo "<form action=\"?op=reg\" method=\"POST\">\n"; echo "Username: <input name=\"username\" MAXLENGTH=\"16\"><br />\n"; echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"><br />\n"; echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"><br />\n"; echo "<input type=\"submit\">\n"; echo "</form>\n"; } ?> login.php <?php session_start(); include "db_connect.inc.php"; if ($_GET["op"] == "login") { if (!$_POST["username"] || !$_POST["password"]) { die("You need to provide a username and password."); } $q = "SELECT * FROM `members` " ."WHERE `username`='".$_POST["username"]."' " ."AND `password`=PASSWORD('".$_POST["password"]."') " ."LIMIT 1"; $r = mysql_query($q); if ( $obj = @mysql_fetch_object($r) ) { $_SESSION["valid_id"] = $obj->id; $_SESSION["valid_user"] = $_POST["username"]; $_SESSION["valid_time"] = time(); Header("Location: index.php"); } else { die("Sorry, could not log you in. Wrong login information."); } } else { echo "<form action=\"?op=login\" method=\"POST\">"; echo "Username: <input name=\"username\" size=\"15\"><br />"; echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />"; echo "<input type=\"submit\" value=\"Login\">"; echo "</form>"; } ?> logout.php <?php session_start(); session_unset(); session_destroy(); Header("Location: index.php"); ?>
  9. How would you go about doing that? I'm going to do research, but incase you post it before I figure it out.
  10. <?php include ("db_connect.inc.php"); if ( $_GET["op"] == "reg" ) ---------------------------11 { $bInputFlag = false; foreach ( $_POST as $field ) { if ($field == "") { $bInputFlag = false; } else { $bInputFlag = true; } } if ($bInputFlag == false) { die( "Problem with your registration info. " ."Please go back and try again."); } $q = "INSERT INTO `members` (`username`,`password`,`email`) " ."VALUES ('".$_POST["username"]."', " ."PASSWORD('".$_POST["password"]."'), " ."'".$_POST["email"]."')"; $r = mysql_query($q); if ( !mysql_insert_id() ) { die("Error: User not added to database."); } else { Header("Location: register.php?op=thanks"); } } elseif ( $_GET["op"] == "thanks" ) ------------------------------- 55 { echo "<h2>Thanks for registering!</h2>"; } else { echo "<form action=\"?op=reg\" method=\"POST\">\n"; echo "Username: <input name=\"username\" MAXLENGTH=\"16\"><br />\n"; echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"><br />\n"; echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"><br />\n"; echo "<input type=\"submit\">\n"; echo "</form>\n"; } // EOF ?> Notice: Undefined index: op in ..website.. on line 11 Notice: Undefined index: op in ..website.. on line 55 Marked #s
  11. Thanks, I'll try to sort it out.
  12. <?php if (!isLoggedIn()) { if (isset($_POST['cmdlogin'])) { if (checkLogin($_POST['username'], $_POST['password'])) { show_userbox(); } else { echo "Incorrect Login information !"; show_loginform(); } } else { show_loginform(); } } else { show_userbox(); } ?> Fatal error: Call to undefined function isLoggedIn() in ..website name.. on line 2
  13. Ego. I agree PHP is no where near the most difficult, but it certainly is not a toy. I think he is probably basing this off of the syntax as well, comparing c++ and php at a glance possibly? Just ignore the guy.
  14. Thanks, and I completely understand, you don't need to write me a script, just looking for some guidance. And I would do the tutorials here, but it's down isn't it?
  15. www.allaboutexotics.co.uk/main.php This is the general direction I am heading in, I am doing reading, and slowly figuring it all out, but is there a relatively generic script that generates something similar to the link above. Thanks, sorry if this is a little misguided, I'm trying to speed up my learning, and I think having my hands on a script like that would help.
  16. You were right, it worked, and I had discovered my error as well, so great, it's fixed. Thank you.
  17. Yes, everything is linked, and attached, and everything is running correctly, I think it's an error in my PHP somewhere, fogetting something... or something is incorrect.
  18. Actually spoke too soon. PHP echo '<table>'; $tr=1; while ($row = mysql_fetch_array($result)) { echo '<tr class="tr' . $tr . '"><td>' . $row["name"] . " says: <br>" . $row['commentdate'] . "<br>" . $row['commenttext'] . '</td></tr>'; if($tr==1){ $tr=2; } else if( $tr==2){ $tr=1; } } echo '</table>'; CSS nth-child(odd) { background: #CCC; } nth-child(even) { background: #FFF; } Everything is loading correctly, it is just not displaying the color.
  19. I can always count on you guys Thanks Topic Solved.
  20. I have been currently working out the look of my site, trying to wrap my head around it and all, and I've seen it on a couple of websites, and I'm curious how it is done. I would like to know how an alternating bg color on tables works, this is going to be used specifically for my comments portion, but it could be applied to anywehere. I'm curious as o if it is done purely with PHP, or both CSS, and PHP. For example, to clarify myself: Table A bg=grey bg=white bg=grey bg=white etc.. Thanks, I'll clarify anything I can if that does not make sense.
  21. I'm not sure exactly what it is called, but here is an example of it.. http://ronpaulmarch.com/ scroll half way down and there is a list of 20 cities, with an alternating grey and white background. I'm curious how that is done, with both CSS or PHP, or both. I already have tables set up for comments on my own project and I'm looking alternate the background colors, for more appeal to the section. Thanks. Sorry if the question is inadequate. Wasn't sure how to ask
  22. I've been searching for some good relatively short code for a 'remember me', but I just can't find one. If you guys have any code, or any links to a good tutorial, it would be much appreciated. Thanks.
  23. Alright ill try that. $query = "select * from users where username='$username' and password='$password'"; echo "$query<br>"; if(isset($query)) { echo 'query is set'; } select * from users where username='a' and password='0cc175b9c0f1b6a831c399e269772661' query is set
×
×
  • 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.