Jump to content

lAZLf

Members
  • Posts

    89
  • Joined

  • Last visited

    Never

Everything posted by lAZLf

  1. I see what you mean, but wouldn't the fact that it's in a "while" statement (original code) get in the way?
  2. What do you mean when you say "with a link for the Archive table"? And how could I use it in the query?
  3. SELECT * FROM Archive ORDER BY date DESC My table for the posts has the columns of "title", "content" and "date". That part works fine (http://annarboruncovered.com/). I'm going to set up a table for the comments with the columns of "content", "poster" and "date".
  4. on my website, I display posts/updates on the website's development, and I'm trying to make it so that with each post, a viewer can post a comment on it. I can't figure out how to make it so that each post can show different comments. sorry if i'm not being so clear. where the posts are displayed: while($row=mysql_fetch_array($result)){ echo' <tr> <td height="20" class="title">'.$row['title'].'</td><td class="title"><div align="right">'.$row['date'].' </div> </td> </tr> <tr> <td height="100" colspan="2" class="content">'.$row['content'].' </td> </tr> <tr><td> <a href="javascript:toggle_visibility()" class="link">[comments]</a> <div id="comments">hi</div> </td></tr>'; }
  5. My website site is mainly many, many tables. In a row, if something's bigger in one column than the other thing in the other column, the smaller thing is vertically centered. How could I avoid that? http://annarboruncovered.com/ ^On the top where the links are, they're centered due to the login form. EDIT: I figured it out. vertical-align in css
  6. I just figured out that meant using the sha1(); function. So yes, it's hashed. Now that i've hashed it, it works. Now I have a new problem, which is probably a newby mistake. When it goes back to the previous page via header location, I noticed that either the login.php page didn't set the session, or the index.php page didn't check for it properly. login.php: <?php session_start(); // dBase file include "dbConfig.php"; // Create query $q = "SELECT * FROM people WHERE username='".$_POST["username"]."' AND password = sha1('".$_POST["password"]."')"; // Run query $r = mysql_query($q,$ms) or trigger_error (mysql_error()); $rowCheck = mysql_num_rows($r); if($rowCheck > 0){ while($row = mysql_fetch_array($r)){ // Login good, create session variables $_SESSION["valid_user"] = $_POST["username"]; // Redirect to member page header ("location: index.php"); } } else { //if nothing is returned by the query, unsuccessful login code goes here... echo 'Incorrect login name or password. Please try again.'; } echo '<pre>Query: '. $q .'</pre>'; ?> index.php: <?php if (!$_SESSION['valid_user']) { echo' <form action="login.php" method="post"> <table cellspacing="0"> <tr><td><input type="text" name="username"width="300" value="username"/></td></tr> <tr><td><input type="password" name="password"width="300" value="password"/></td></tr> <tr><td><input type="submit" value="login"/></td></tr> </table> </form> '; } else { echo"Welcome".$_SESSION['valid_user']; } ?>
  7. What do you mean by hash? And how would I do it?
  8. Alright I did what mrMarcus said. I got back: "Incorrect login name or password. Please try again. Query: SELECT * FROM people WHERE username='username' AND password = PASSWORD('password')" It all matches up.
  9. I'm receiving the actual message. If I was being redirected, it would be to the homepage where it checks if the session variable is stored and displays content accordingly.
  10. I changed "login.php" again, and now i'm sure that the "if" statement isn't working right, I enter in the correct information and it always sais I didn't. Should I change something in the "if" statement? <?php session_start(); // dBase file include "dbConfig.php"; // Create query $q = "SELECT * FROM people WHERE username='".$_POST["username"]."' AND password = PASSWORD('".$_POST["password"]."')"; // Run query $r = mysql_query($q, $ms); $rowCheck = mysql_num_rows($r); if($rowCheck > 0){ while($row = mysql_fetch_array($r)){ // Login good, create session variables $_SESSION["valid_user"] = $_POST["username"]; // Redirect to member page header ("location: index.php"); } } else { //if nothing is returned by the query, unsuccessful login code goes here... echo 'Incorrect login name or password. Please try again.'; } ?>
  11. Thanks, I don't get that error anymore, but even when I enter in the correct name and password I can't get in. I changed a the code a bit: <?php session_start(); // dBase file include "dbConfig.php"; // Create query $q = "SELECT * FROM `people` " ."WHERE `username`='".$_POST["username"]."' " ."AND `password`=PASSWORD('".$_POST["password"]."') " ."LIMIT 1"; // Run query $r = mysql_query($q); if ( $obj = @mysql_fetch_object($r)) { // Login good, create session variables $_SESSION["valid_user"] = $_POST["username"]; // Redirect to member page header ("location: index.php"); } else { // Login not successful die("Sorry, could not log you in. Wrong login information."); } ?> I'm gonna guess the problem is with the if statement (well, it always go to the else statement). What's wrong with it. (try to explain it if you can, i'm still learning about PHP)
  12. dbConfig.php <? // Replace the variable values below // with your specific database information. $host = "localhost"; $user = "username"; $pass = "password"; $db = "annarbo1_Archives"; // This part sets up the connection to the // database (so you don't need to reopen the connection // again on the same page). $ms = mysql_pconnect($host, $user, $pass); if ( !$ms ) { echo "Error connecting to database.\n"; } // Then you need to make sure the database you want // is selected. mysql_select_db($db); ?> login.php <?php // dBase file include "dbConfig.php"; session_start(); if ($_GET["op"] == "login") { if (!$_POST["username"] || !$_POST["password"]) { die("You need to provide a username and password."); } // Create query $q = "SELECT * FROM `people` " ."WHERE `username`='".$_POST["username"]."' " ."AND `password`=PASSWORD('".$_POST["password"]."') " ."LIMIT 1"; // Run query $r = mysql_query($q); if ( $obj = @mysql_fetch_object($r) ) { // Login good, create session variables $_SESSION["valid_user"] = $_POST["username"]; // Redirect to member page Header("Location: index.php"); } else { // Login not successful die("Sorry, could not log you in. Wrong login information."); } } ?> when I run this online i get this error: "Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home4/annarbo1/public_html/login.php:2) in /home4/annarbo1/public_html/login.php on line 4" I have yet to figure out what's wrong
  13. that still doesn't work.... ??? screenbreaker.com/view.php
  14. i was making a little PHP chat thing so i can view peoples comments... but it doesnt seem to work. here's the code for the code to insert stuff into data base: PHP Code: <?php $mysqli = mysqli_connect("localhost", "XXXXXXX", "XXXXXXX", "XXXXXXX"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $sql = "INSERT INTO testTable (testField) VALUES ('".$_POST["testfield"]."')"; $res = mysqli_query($mysqli, $sql); if ($res === TRUE) { echo "A record has been inserted.<br/> <a href='view.php'>click here</a> to view messages"; } else { printf("Could not insert record: %s\n", mysqli_error($mysqli)); } mysqli_close($mysqli); } ?> and here's the code to view the comments: PHP Code: <?php $mysqli = mysqli_connect("localhost", "XXXXXXX", "XXXXXXX", "XXXXXXX"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $sql = "SELECT * FROM testTable"; $res = mysqli_query($mysqli, $sql); if ($res) { while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) { $id = $newArray['id']; $testField = $newArray['testfield']; echo "The ID is ".$id." and the text is ".$testField."<br/>"; } } else { printf("Couldn't retrieve records: %s\,", mysqli_error($mysqli)); } mysqli_free_result($res); mysqli_close($mysqli); } ?> but when i view the PHP in the browser it doesn't show the message but there's no error message.... mind helping me out? if you would like to see the result go to http://screenbreaker.com/view.php
×
×
  • 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.