Jump to content

wargolchaos

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

About wargolchaos

  • Birthday 02/16/1989

Contact Methods

Profile Information

  • Gender
    Male
  • Location
    Chicago

wargolchaos's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. How can I make this work with what I have set up? Do I tie $excerpt to my query statement some how?
  2. In case the topic didn't say it all I am looking for a way to limit the amount of text I pull from the database to display on my news page. The goal is to display a small peice of the news and then add a read more link which will go to another page and load up the article. The read more I can handle but limiting the text for the front page has me stumped at the moment. Heres my MySQL code. $maxRows_rsNews = 10; $pageNum_rsNews = 0; if (isset($_GET['pageNum_rsNews'])) { $pageNum_rsNews = $_GET['pageNum_rsNews']; } $startRow_rsNews = $pageNum_rsNews * $maxRows_rsNews; mysql_select_db($database_conndb, $conndb); $query_rsNews = "SELECT * FROM tbl_news ORDER BY id DESC"; $query_limit_rsNews = sprintf("%s LIMIT %d, %d", $query_rsNews, $startRow_rsNews, $maxRows_rsNews); $rsNews = mysql_query($query_limit_rsNews, $conndb) or die(mysql_error()); $row_rsNews = mysql_fetch_assoc($rsNews); if (isset($_GET['totalRows_rsNews'])) { $totalRows_rsNews = $_GET['totalRows_rsNews']; } else { $all_rsNews = mysql_query($query_rsNews); $totalRows_rsNews = mysql_num_rows($all_rsNews); } $totalPages_rsNews = ceil($totalRows_rsNews/$maxRows_rsNews)-1; Thanks for any help in advance.
  3. Thanks, instead of making my code any more complex I just added a link that leads back to the same page. This way it refreshes.
  4. Yeah, I should start doing that. Maybe i'll take a walk around the block or something. I've really been hard core about learning and working with PHP.
  5. Is there any good way to refresh a page without using header:location?
  6. Thanks, your pinned it. Sitting here working on this website for so long has me blind.
  7. Its not working. Heres what the entire script looks like. <?php if(isset($_SESSION["level"])) { echo '<h3>Admin</h3> <p>This is an example of a content page!</p>'; echo '<h3>Welcome '.$_SESSION["name"].', your user level is '.$_SESSION["level"]; } else { include('db_info.php'); connectDB(); selectDB("-----"); if(isset($_POST['email']) && isset($_POST['password'])){ // Verify $email = mysql_escape_string($_POST['email']); $password = md5($_POST['password']); $gUser = mysql_query("SELECT * FROM users WHERE email='".$email."' AND password='".$password."' LIMIT 1") or die(mysql_error()); $verify = mysql_num_rows($gUser); if($verify > 0){ /*Set user level*/ $row = mysql_fetch_assoc($gUser); $_SESSION["level"] = $_row["level"]; $_SESSION["name"] = $email; /*End of set user level*/ echo '<h2>Login Complete</h2>'; echo '<h3>Welcome '.$_SESSION["name"].', your user level is '.$_SESSION["level"]; }else{ /* If login fails> */ echo '<h2>Login Failed</h2> <p>Sorry your login credentials are incorrect. <a href=\"admin.php\">Try again</a><br /><br />'; } }else{ ?> heres what my db looks like $sql ="CREATE TABLE users ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) NOT NULL, email VARCHAR(50) NOT NULL, password VARCHAR(32) NOT NULL, date DATE NOT NULL, level INT NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
  8. Goal assign user level into a session when a user logs in. login mysql code: // Verify $email = mysql_escape_string($_POST['email']); $password = md5($_POST['password']); $gUser = mysql_query("SELECT * FROM users WHERE email='".$email."' AND password='".$password."' LIMIT 1") or die(mysql_error()); $verify = mysql_num_rows($gUser); if($verify > 0){ echo '<h2>Login Complete</h2>'; }else{ echo '<h2>Login Failed</h2> <p>Sorry your login credentials are incorrect.<br /><br />'; } So what I need to do is assign a level variable, This is what I'm thinking. $level = (a db query) [-the level will be between 1 and 5-] then assign it to a session var $_SESSION["level"] = $level So I am looking to learn a reliable way to set this variable and have it stick as a session.
  9. Thanks guys, I got it now. I found my error. $username = mysql_escape_string($_POST['username']); $password = md5($_POST['password']); It was the md5(password) Thanks again!
  10. $gUser = mysql_query("SELECT * FROM test WHERE username='".$username."' AND password='".md5($password)."' LIMIT 1") or die(mysql_error()); Sorry, this is the code im using. By mistake I posted the version that I switched for testing.
  11. My script works without the md5 but not with the md5. I cant figure out what im doing wrong. Its driving me crazy.. Please help. Heres my sql. CREATE TABLE `users` ( `id` int(10) NOT NULL auto_increment, `username` varchar(50) NOT NULL, `password` varchar(32) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; Heres how I added a single user to test the database. <?php mysql_connect("localhost", "----", "----") or die(mysql_error()); mysql_select_db("-------") or die(mysql_error()); $username = 'testuser'; $password = 'testpass'; mysql_query("INSERT INTO test (username, password) VALUES('". mysql_escape_string($username) ."', '".md5($password)."' ) ") or die(mysql_error()); ?> And here is my login script <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <div id="wrap"> <?php mysql_connect("localhost", "-----", "-----") or die(mysql_error()); mysql_select_db("--------") or die(mysql_error()); if(isset($_POST['username']) && isset($_POST['password'])){ // Verify $username = mysql_escape_string($_POST['username']); $password = $_POST['password']; $gUser = mysql_query("SELECT * FROM test WHERE username='".$username."' AND password='".$password."' LIMIT 1") or die(mysql_error()); $verify = mysql_num_rows($gUser); if($verify > 0){ echo '<h2>Login Complete</h2> <p>Thanks for logging in!</p>'; }else{ echo '<h2>Login Failed</h2> <p>Sorry your login credentials are incorrect.'; } }else{ ?> <h2>Login</h2> <p>Please enter your login credentials to get access to the download area</p> <form method="post" action=""> <fieldset> <label for="username">Username:</label><input type="text" name="username" value="" /> <label for="password">Password:</label><input type="text" name="password" value="" /> <input type="submit" value="Login" /> </fieldset> </form> <?php } ?> </div> </body> </html>
×
×
  • 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.