Jump to content

SauloA

Members
  • Posts

    54
  • Joined

  • Last visited

    Never

Everything posted by SauloA

  1. There's still an error with: if (!mysql_num_rows()){ print "no such login in the system. please try again."; exit(); } in your code thorpe.
  2. The part of my code that says: if(mysql_affected_rows()==0){ print "no such login in the system. please try again."; exit(); is working is displaying "no such login in the system. please try again." as it should display if there is an error. I don't know what the error is though.
  3. I don't know what the problem is. I'm assuming that there's somthing wrong with my code. Maybe somebody can tell me what's missing or how to fix it.
  4. I'm trying to create a form that will that will send a user their password through an email. The user is supposed to put their username in the text box and than get an email with their login information. Here's my code. The problem seems to be this code. I'd appreciate the help. mysql_select_db($database_connBlog, $connBlog); $sql="SELECT user_pass, user_email FROM user_tbl WHERE user_sname='".$user_sname."'"; $r = mysql_query($sql, $connBlog); if(!$r) { $err=mysql_error(); print $err; exit(); } if(mysql_affected_rows()==0){ print "no such login in the system. please try again."; exit(); } else { $row=mysql_fetch_array($r); $password=$row["user_pass"]; $email=$row["user_email"]; $subject="your password"; $header="from:[email protected]"; $content="your password is ".$password; mail($email, $subject, $row, $header); print "An email containing the password has been sent to you"; } Here's the form where the usename is inputted. <form name="forgot" method="post" action="forgot.php"> <input name="sname" type="text" value="user_sname" size="20"/><br /> <input type="submit" name="submit" value="submit"/> <input type="reset" name="reset" value="reset"/> </form> If this isn't a good way of sending login information. Can someone send me in the right dircetion?
  5. That code worked perfectly jesirose. So far most or all of the problems I've posted on PHP Freaks have been solved by you. Thanks a bunch.
  6. I'm essentially trying to check is there is anything in my session variable. If my session variable is empty then it should display the login form. If there is something in the session variable then the login form should no longer display and "Welcome 'username' " should appear. My " if " statement begins here: <?php if ($_SESSION['MM_Username'] == 0) { ?> <form ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" name="frmLogin" id="frmLogin"> <table> <caption> Login to the site </caption> <tr> <th align="right" scope="row">Username:</th> <td><input name="username" type="text" id="username" size="10" maxlength="10" /></td> </tr> <tr> <th align="right" scope="row">Password:</th> <td><input name="password" type="password" id="password" size="10" maxlength="10" /></td> </tr> <tr> <th align="right" scope="row"> </th> <td><input type="submit" name="Submit" value="Login" /></td> </tr> </table> </form> <?php } else { ?> <p>Welcome <?php echo $_SESSION['MM_Username']; ?></p> <?php } ?> but I don't know how to do what I explained above.
  7. Well, I changed: if(!isset($_SESSION)) { session_start(); } into: session_start(); and I get no errors and the page works fine. But, that wasn't the issue I was trying to solve. I want the login form to appear when a user isn't logged in. If a user is logged in then the form should be hidden and "Welcome username" should appear.
  8. I change: if (!isset($_SESSION)) { session_start(); } into: if (!isset($_SESSION)) { session_start() } and I get an error on my page. When I change it back, I no longer have the error.
  9. The problem isn't in the: if (!isset($_SESSION)) { session_start(); } The problem is most likely in this region near the bottom: <?php if ($_SESSION['MM_Username'] == 0) { ?> <form ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" name="frmLogin" id="frmLogin"> <table> <caption> Login to the site </caption> <tr> <th align="right" scope="row">Username:</th> <td><input name="username" type="text" id="username" size="10" maxlength="10" /></td> </tr> <tr> <th align="right" scope="row">Password:</th> <td><input name="password" type="password" id="password" size="10" maxlength="10" /></td> </tr> <tr> <th align="right" scope="row"> </th> <td><input type="submit" name="Submit" value="Login" /></td> </tr> </table> </form> <?php } else { ?> <p>Welcome <?php echo $_SESSION['MM_Username']; ?></p> <?php } ?>
  10. I've created a login in page and I want the login form to appear when a user isn't logged in and hide the login form and displaying the username when the user is logged in. I think I'm close to solving the problem but I'm probably missing some code. Here's my code. I'd appreciate the help. <?php require_once('../Connections/connBlog.php'); ?> <?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = "al_levelid"; $MM_redirectLoginSuccess = "home.php"; $MM_redirectLoginFailed = "failed.php"; $MM_redirecttoReferrer = true; mysql_select_db($database_connBlog, $connBlog); $LoginRS__query=sprintf("SELECT user_id, user_sname, user_pass, al_levelid FROM user_tbl WHERE binary user_sname='%s' AND binary user_pass='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $connBlog) or die(mysql_error()); $LoginArray= mysql_fetch_array($LoginRS); //Creates the array $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'al_levelid'); //declare three session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserID'] = $LoginArray['user_id']; $_SESSION['MM_UserLevel'] = $LoginArray['al_levelid']; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && true) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Blog Login</title> <link href="mystyles.css" rel="stylesheet" type="text/css" /> </head> <body> <p><a href="home.php">Reviews</a> | <a href="users.php">Users</a> | <a href="shops.php">Shops</a> | <a href="customers.php">Customers</a> | <a href="subscriptions.php">Subscriptions</a> | <a href="invoices.php">Invoices</a> | <a href="logout.php">Logout</a> </p> <?php if ($_SESSION['MM_Username'] == 0) { ?> <form ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" name="frmLogin" id="frmLogin"> <table> <caption> Login to the site </caption> <tr> <th align="right" scope="row">Username:</th> <td><input name="username" type="text" id="username" size="10" maxlength="10" /></td> </tr> <tr> <th align="right" scope="row">Password:</th> <td><input name="password" type="password" id="password" size="10" maxlength="10" /></td> </tr> <tr> <th align="right" scope="row"> </th> <td><input type="submit" name="Submit" value="Login" /></td> </tr> </table> </form> <?php } else { ?> <p>Welcome <?php echo $_SESSION['MM_Username']; ?></p> <?php } ?> </body> </html>
  11. This has solved my problem. Thanks a bunch.
  12. I've created a login page with the username and password fields but they are not case sensitive. A user can enter their username and password in any fashion they want, all caps, all lower case, etc. and still achieve the same results to login in because the text fields or whatever are not case sensitive. What can I do to achieve my desired results? Here's to code for my entire login page. I'd appreciate the help. <?php require_once('../Connections/connBlog.php'); ?> <?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = "al_levelid"; $MM_redirectLoginSuccess = "home.php"; $MM_redirectLoginFailed = "failed.php"; $MM_redirecttoReferrer = true; mysql_select_db($database_connBlog, $connBlog); $LoginRS__query=sprintf("SELECT user_id, user_sname, user_pass, al_levelid FROM user_tbl WHERE user_sname='%s' AND user_pass='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $connBlog) or die(mysql_error()); $LoginArray= mysql_fetch_array($LoginRS); //Creates the array $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'al_levelid'); //declare three session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserID'] = $LoginArray['user_id']; //Stores the user_id in a session variable. $_SESSION['MM_UserLevel'] = $LoginArray['al_levelid']; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && true) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Blog Login</title> <link href="mystyles.css" rel="stylesheet" type="text/css" /> </head> <body> <form ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" name="frmLogin" id="frmLogin"> <table> <caption> Login to the site </caption> <tr> <th align="right" scope="row">Username:</th> <td><input name="username" type="text" id="username" size="10" maxlength="10" /></td> </tr> <tr> <th align="right" scope="row">Password:</th> <td><input name="password" type="password" id="password" size="10" maxlength="10" /></td> </tr> <tr> <th align="right" scope="row"> </th> <td><input type="submit" name="Submit" value="Login" /></td> </tr> </table> </form> </body> </html>
  13. I took off the "[/url]" from you code and also you forgot to end if with "?>" so I added it.  Other then what I listed, the code worked exactly how I wanted.  Thanks a bunch.
  14. I have a cell in my table where I want to make a link that sends the user to another page on my site.  I want the text in my cell to appear as a link depending on a users access level.  If the user has an access level of 2 there shouldn't be a link otherwise the link does display. Here's some code I've been working on that doesn't work, but is kind of the concept that I want.  I'd appreciate the help. <?php if (!(strcmp($_SESSION['MM_UserLevel'],2))) { echo $row_rsReviews['urev_id']; } else { <a href="editreviews.php?revID=<?php echo $row_rsReviews['urev_id']; ?>"><?php echo $row_rsReviews['urev_date']; ?></a> } ?> The problem is most likely everything after the else statement, but since I'm kinda new to PHP I wouldn't know.
  15. I don't want to use a TIMESTAMP field.  I've looked at that MySQL documentation you have been reading many times when I was learining MySQL.  I don't think that's the best resource.
  16. The website you provided may be good for formatting time but doesn't seem to be good for creating default values.  Unless you know how to manipulate the data on that website to get me the current date and time displayed then I'm out of luck.
  17. How else am I supposed to to get the current date and time then?  If timestamps aren't recommended than what else is there.  This forum records the current date and time when something is posted.  How do I get the same results?
  18. I've been creating and recreating through the process.  But I may be putting the wrong attributes. I've written the code exactly like this: 'urev_date` datetime NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, and without the NOT NULL like this: 'urev_date` datetime default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, And I also tried making the default NOW() along with other default values without NOT NULL. Any ideas?
  19. I removed NOT NULL but I still get an error that the code is invalid.  Any other ideas?
  20. Changing my code to: `urev_date` datetime NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, isn't working.  I get an error in phpMyAdmin saying that the code isn't invalid. Any other ideas?
  21. I've already created the table so how would the code look when using ALTER?
  22. I have a MySQL database and I'm trying to set my datetime fields have a default value of NOW() or CURDATE or something that records the current date/time.  I'm using phpmyadmin and input NOW() and a number of other default values in the default value text box, but I keep getting an error saying that my default value is invalid.  Is there any way to set a default value that records the current date/time on phpMyAdmin or MySQL?  I'd appreciate the help. Here's my table structure.  The [color=red]red[/color] is the datetime field I'm trying to change. CREATE TABLE `user_review_tbl` (  `urev_id` int(11) NOT NULL auto_increment,  `user_id` int(11) NOT NULL,  `urev_review` text NOT NULL,  [color=red]`urev_date` datetime NOT NULL,[/color]  `urev_approved` tinyint(1) default NULL,  `shop_id` int(11) NOT NULL,  PRIMARY KEY  (`urev_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
  23. I have a MySQL database and I'm trying to set my datetime fields have a default value of NOW() or CURDATE or something that records the current date/time.  I'm using phpmyadmin and input NOW() and a number of other default values in the default value text box, but I keep getting an error saying that my default value is invalid.  Is there any way to set a default value that records the current date/time on phpMyAdmin or MySQL?  I'd appreciate the help. Here's my table structure.  The [color=red]red[/color] is the datetime field I'm trying to change. CREATE TABLE `user_review_tbl` (  `urev_id` int(11) NOT NULL auto_increment,  `user_id` int(11) NOT NULL,  `urev_review` text NOT NULL,  [color=red]`urev_date` datetime NOT NULL,[/color]  `urev_approved` tinyint(1) default NULL,  `shop_id` int(11) NOT NULL,  PRIMARY KEY  (`urev_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
  24. I'm still kinda new to PHP so can you elaborate how I would do what you suggest? Where would I put the coding you suggest?
  25. Here's the insertion code I'm using.  I pasted all my code just in case. <?php require_once('../Connections/connBlog.php'); ?> <?php require_once('../Connections/connBlog.php'); ?><?php if (!isset($_SESSION)) {  session_start(); } $MM_authorizedUsers = "1,2"; $MM_donotCheckaccess = "false"; // *** Restrict Access To Page: Grant or deny access to this page function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {  // For security, start by assuming the visitor is NOT authorized.  $isValid = False;  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username.  // Therefore, we know that a user is NOT logged in if that Session variable is blank.  if (!empty($UserName)) {    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login.    // Parse the strings into arrays.    $arrUsers = Explode(",", $strUsers);    $arrGroups = Explode(",", $strGroups);    if (in_array($UserName, $arrUsers)) {      $isValid = true;    }    // Or, you may restrict access to only certain users based on their username.    if (in_array($UserGroup, $arrGroups)) {      $isValid = true;    }    if (($strUsers == "") && false) {      $isValid = true;    }  }  return $isValid; } $MM_restrictGoTo = "default.php"; if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {    $MM_qsChar = "?";  $MM_referrer = $_SERVER['PHP_SELF'];  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)  $MM_referrer .= "?" . $QUERY_STRING;  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);  header("Location: ". $MM_restrictGoTo);  exit; } ?><?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;  switch ($theType) {    case "text":      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";      break;        case "long":    case "int":      $theValue = ($theValue != "") ? intval($theValue) : "NULL";      break;    case "double":      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";      break;    case "date":      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";      break;    case "defined":      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;      break;  }  return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) {  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {  $insertSQL = sprintf("INSERT INTO user_review_tbl (urev_date, shop_id, urev_approved, user_id, urev_review) VALUES (%s, %s, %s, %s, %s)",                       GetSQLValueString($_POST['urev_date'], "text"),                       GetSQLValueString($_POST['shop_id'], "int"),                       GetSQLValueString(isset($_POST['urev_approved']) ? "true" : "", "defined","1","0"),                       GetSQLValueString($_POST['user_id'], "int"),                       GetSQLValueString($_POST['urev_review'], "text"));  mysql_select_db($database_connBlog, $connBlog);  $Result1 = mysql_query($insertSQL, $connBlog) or die(mysql_error());  $insertGoTo = "home.php";  if (isset($_SERVER['QUERY_STRING'])) {    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";    $insertGoTo .= $_SERVER['QUERY_STRING'];  }  header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_connBlog, $connBlog); $query_rsShop = "SELECT shop_id, shop_name FROM shop_tbl ORDER BY shop_name ASC"; $rsShop = mysql_query($query_rsShop, $connBlog) or die(mysql_error()); $row_rsShop = mysql_fetch_assoc($rsShop); $totalRows_rsShop = mysql_num_rows($rsShop); $maxRows_rsReviews = 10; $pageNum_rsReviews = 0; if (isset($_GET['pageNum_rsReviews'])) {  $pageNum_rsReviews = $_GET['pageNum_rsReviews']; } $startRow_rsReviews = $pageNum_rsReviews * $maxRows_rsReviews; mysql_select_db($database_connBlog, $connBlog); $query_rsReviews = "SELECT urev_id, urev_date, urev_approved, shop_id FROM user_review_tbl ORDER BY urev_date DESC"; $query_limit_rsReviews = sprintf("%s LIMIT %d, %d", $query_rsReviews, $startRow_rsReviews, $maxRows_rsReviews); $rsReviews = mysql_query($query_limit_rsReviews, $connBlog) or die(mysql_error()); $row_rsReviews = mysql_fetch_assoc($rsReviews); if (isset($_GET['totalRows_rsReviews'])) {  $totalRows_rsReviews = $_GET['totalRows_rsReviews']; } else {  $all_rsReviews = mysql_query($query_rsReviews);  $totalRows_rsReviews = mysql_num_rows($all_rsReviews); } $totalPages_rsReviews = ceil($totalRows_rsReviews/$maxRows_rsReviews)-1; ?>
×
×
  • 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.