Jump to content

mysty

Members
  • Posts

    83
  • Joined

  • Last visited

    Never

Posts posted by mysty

  1. I may not have explained this very well.  Instead of looking up what specifiers to put for dates, this small program did it for you.  It didn't put it into the PHP code.  For that, you just copied the output into your own code.  For example if I wanted a date output to say Nov 11, 2007 , I would need to put in my code

    %b %d, %Y.  So, this little stand alone program would have blanks for you to fill out for Month, Day, Year and you would put Nov in Month, 11 for Day, and 2007 for Year and it would show you %b %d %Y.  I think it even had a place to put dashes or slashes (ie: 11-11-07  or  11/11/07) and it would show you all the specifiers you need to use.

  2. I used to have (but lost) a small program for date and time format help.  Once started, you could input date and time info and it would show the codes needed.  It also had a choice between PHP or MySQL as the output code.  Anybody know what this is or where I can find it?

  3. <?php echo $_SESSION['MY_date'] ?>

     

    This is line of code that gets a date from a session variable. The session variable, MY_date, comes from a database DATE field.

    The output is like this: 2007-01-01. What I want the output to look like is this: January 1, 2007.

    How do I do that? or what changes are needed in the above code?

  4. <?php require_once('Connections/conn_tester.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
    }
    }
    ?><?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 = "status";
      $MM_redirectLoginSuccess = "welcome.php";
      $MM_redirectLoginFailed = "failed_login.php";
      $MM_redirecttoReferrer = false;
      mysql_select_db($database_conn_tester, $conn_tester);
      	
      $LoginRS__query=sprintf("SELECT username, password, status FROM `user` WHERE username=%s AND password=%s",
      GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
       
      $LoginRS = mysql_query($LoginRS__query, $conn_tester) or die(mysql_error());
      $loginFoundUser = mysql_num_rows($LoginRS);
      if ($loginFoundUser) {
        
        $loginStrGroup  = mysql_result($LoginRS,0,'status');
        
        //declare two session variables and assign them
        $_SESSION['MM_Username'] = $loginUsername;
        $_SESSION['MM_UserGroup'] = $loginStrGroup;	      
    
        if (isset($_SESSION['PrevUrl']) && false) {
          $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">
    

    Attached above is the code for a login page.  It is setup using Dreamweaver so that it checks a field in my MySQL database called status in which it has numbers from 1 to 3 for gaining access to the site.  What I want to do is modify the code so that it checks the "today's date" versus a DB field called plus_date.  If the plus_date minus todays date is greater than one, access is gained.

     

    Listed below is a portion of the page that I am trying to restrict access to.  I will need to modify this code also, but am not sure how to that.  Anybody help with a little code modification?

     

    <?php
    if (!isset($_SESSION)) {
      session_start();
    }
    $MM_authorizedUsers = "3";
    $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 = "login.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;
    }
    ?>
    

  5. Here is the code.  It is everything from line 1 to the DOC declaration, which I left in the first line.

    <?php require_once('../Connections/con_cpg.php'); ?>
    <?php
    if (!isset($_SESSION)) {
      session_start();
    }
    $MM_authorizedUsers = "9";
    $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 = "../admin/admin_login.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
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
    }
    }
    
    $colname_data_list = "-1";
    if (isset($_GET['recordid'])) {
      $colname_data_list = (get_magic_quotes_gpc()) ? $_GET['recordid'] : addslashes($_GET['recordid']);
    }
    mysql_select_db($database_con_cpg, $con_cpg);
    $query_data_list = sprintf("SELECT * FROM tbl_data WHERE recordid = %s", GetSQLValueString($colname_data_list, "int"));
    $data_list = mysql_query($query_data_list, $con_cpg) or die(mysql_error());
    $row_data_list = mysql_fetch_assoc($data_list);
    $totalRows_data_list = mysql_num_rows($data_list);
    
    $maxRows_data_list = 100;
    $pageNum_data_list = 0;
    if (isset($_GET['pageNum_data_list'])) {
      $pageNum_data_list = $_GET['pageNum_data_list'];
    }
    $startRow_data_list = $pageNum_data_list * $maxRows_data_list;
    
    mysql_select_db($database_con_cpg, $con_cpg);
    $query_data_list = "SELECT lastname, firstname, title, company, products, email, entered, recordid FROM tbl_data GROUP BY lastname, firstname, email, lastname HAVING (COUNT(*) > 1)";
    $query_limit_data_list = sprintf("%s LIMIT %d, %d", $query_data_list, $startRow_data_list, $maxRows_data_list);
    $data_list = mysql_query($query_limit_data_list, $con_cpg) or die(mysql_error());
    $row_data_list = mysql_fetch_assoc($data_list);
    ?>
    <?php
    // start the dupes routine
    $query = 'SELECT email, COUNT(*) AS cnt FROM tbl_data GROUP BY email HAVING cnt > 1 ';
    $result = mysql_query($query) or die($query."<br />\n".mysql_error());
    $dups = array();
    while ($row = mysql_fetch_assoc($result))
    {
        $dups[] = $row['email'];
    }
    $query = 'SELECT * FROM tbl_data WHERE email IN ("'.implode('","', $dups).'") ';
    $result = mysql_query($query) or die($query."<br />\n".mysql_error());
    ?>
    
    <?php
    if (isset($_GET['totalRows_data_list'])) {
      $totalRows_data_list = $_GET['totalRows_data_list'];
    } else {
      $all_data_list = mysql_query($query_data_list);
      $totalRows_data_list = mysql_num_rows($all_data_list);
    }
    $totalPages_data_list = ceil($totalRows_data_list/$maxRows_data_list)-1;
    ?>
    
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    

     

  6. I went back and used a clean page.  That is, the webpage I was using had several different thing I had tried, so probably had some remnants of who knows what.  When I tried the clean page, I got the dupe listing like before - a list with all the dupes, one at a time.  I moved the new code snippet around and got the same thing.  Would it help if I posted the section of code?

  7. I put it in the page that outputs the results.  The code snippet went after the require once connection snippet and before the DOC statement.  Here is the error message.

     

    SELECT email, COUNT(*) AS cnt FROM tbl_data GROUP BY email HAVING cnt > 1 
    No Database Selected
    

  8. I called my hosting company and they said they will be upgrading eventually.  Didn't sound like it was going to be too soon.  They said that I could upgrade to a dedicated server which means my monthly fee will multiply by about 10 to 15 times the current rate.  Guess I won't be upgrading - I may be back to this group with my question sometime in the future.  Hope it's in my lifetime.

  9. Here is the query copied from my recordset.

    SELECT td.* FROM tbl_data AS td JOIN (    SELECT lastname, email,  MID(firstname,1,1) AS firstinit
    FROM tbl_data
    GROUP BY lastname, email, init
    HAVING (COUNT(*) > 1) ) AS sub ON td.lastname = sub.lastname AND td.email = sub.email  AND  MID(td.firstname,1,1) = sub.firstinit
    

     

    Here is the error message when the page is run:

    You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT lastname, email, MID(firstname,1,1) AS firstinit FROM t
    

     

    Let me know if there is any other info you need to troubleshoot this.

     

  10. SELECT lastname, firstname, title, email, recordid

    FROM tbl_data

    GROUP BY lastname, firstname, email, lastname

    HAVING (COUNT(*) > 1)

     

     

    Here is the query (recordset in Dreamweaver) that I am using.  It lists all my dupes.  I would like to be able to list all the dupes, except list both dupes.  That is, instead of listing three dupes - smith, jones, brown, my list would show both smiths, both jones, both browns.

    What changes are needed in my query?

    I am using Dreamweaver 802, PHP, MySQL.

  11. Here is the code for the whole page.  Guess I should have put that in the first message instead of just a portion. This part of the code:  <?php echo Date("Y-m-d");?>  was put there just to test whether anything was being put into the database and that part does work, although it is not what I want in the long run.  What I want is, not todays date, but the date plus 30, 60, or 90 days.

     

    When I run the page (fill in the form and choose one option from the list box, then submit) the database is filled with the firstname and lastname.  If I choose 30 or 60 days (see code below) I get todays date in the DB.  If I choose 90 days, I get in the plus_date column "0000-00-00".  I do not get any errors when the page is run.

     

     

    <?php require_once('Connections/conn_tester.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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"] == "newuser")) {
      $insertSQL = sprintf("INSERT INTO `user` (firstname, lastname, plus_date) VALUES (%s, %s, %s)",
                           GetSQLValueString($_POST['firstname'], "text"),
                           GetSQLValueString($_POST['lastname'], "text"),
                           GetSQLValueString($_POST['plus_date'], "date"));
    
      mysql_select_db($database_conn_tester, $conn_tester);
      $Result1 = mysql_query($insertSQL, $conn_tester) or die(mysql_error());
    }
    
    mysql_select_db($database_conn_tester, $conn_tester);
    $query_Recordset1 = "SELECT plus_date FROM `user`";
    $Recordset1 = mysql_query($query_Recordset1, $conn_tester) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    
    if (!session_id()) session_start();
    if (isset($_POST["Submit"]))     {
      $_SESSION["fname"] = "".((isset($_POST["firstname"]))?$_POST["firstname"]:"")  ."";
    }
    
    if (!session_id()) session_start();
    if ($_SERVER["REQUEST_METHOD"] == "POST")     {
      $_SESSION["lname"] = "".((isset($_POST["lastname"]))?$_POST["lastname"]:"")  ."";
    }
    ?><!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>Registration Page - CPG Database</title>
    <table width="750" border="0" align="center">
      <tr>
        <td><div align="center" class="pageName style4">New User Registration </div></td>
      </tr>
      <tr>
        <td class="subHeader"><form action="<?php echo $editFormAction; ?>" method="POST" name="newuser" class="services-red" id="newuser">
          <label><span class="style3"><br />
          </span><br />
          <br />
          <br />
           First Name 
           <input name="firstname" type="text" id="firstname" size="70" />
          </label>
          <p>
            <label> Last Name
            
            <input name="lastname" type="text" id="lastname" size="70" />
            </label>
          </p>
          <p>
            <label></label>
            How many days?
            <select name="plus_date" id="plus_date">
              <option value=" " selected="selected">Please choose one</option>
              <option value="<?php echo Date("Y-m-d");?>">30 Days</option>
              <option value="<?php echo Date("Y-m-d");?>">60 Days</option>
    	  <option value="NOW() + INTERVAL 90 DAY">90 Days</option>
            </select>
    </p>
          <p>
            <input type="submit" name="Submit" value=" Register New User " />
          </p>
          
          
          
          <input type="hidden" name="MM_insert" value="newuser">
        </form>
        <p> </p>    </td>
      </tr>
      <tr>  </tr>
    </table>
    <br />
    <br />
    </body>
    </html>
    <?php
    mysql_free_result($Recordset1);
    ?>
    

  12. I have a short list box with choices for entering dates into a MySQL database.  Attached is a portion of the code for the list box.

     

    How many days?
            <select name="plus_date" id="plus_date">
              <option value=" " selected="selected">Please choose one</option>
              <option value="<?php echo Date("Y-m-d");?>">30 Days</option>
              <option value="NOW() + INTERVAL 90 DAY">90 Days</option>
            </select>
    

     

    The code for 30 days is just a test piece of code which puts in todays date in the correct database column and that works like it should.  What I want to be able to do, is to put in the column, the date plus 30 days or the date plus 90 days.  So, what code do I need for the 90 days line of code?  Once I get the correct code, I will change the "30 day" line so it inputs the date plus 30 days.

×
×
  • 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.