Jump to content

Eiolon

Members
  • Posts

    358
  • Joined

  • Last visited

Posts posted by Eiolon

  1. I am working on a calendar but am having difficulty finding a way to loop the events through the concatenation.  Having it loop on the outside of the string brings only the first event for the day, not all of them.  If I loop outside of the string of $week outputs all the events but it creates a new "day" square for each event.  Thanks for your advice.

    for ($day = 1; $day <= $count_days; $day++, $str++) {
         
        $date = $year_month . '-' . $day;
    
    	$sth_events = $dbh_mysql->prepare("
    		SELECT 
    			id, name, date_time
    		FROM
      			events
     		WHERE
    			date_time LIKE '$date%'
    	");
    	$sth_events->execute();	
    	
    	while ($row_events = $sth_events->fetch(PDO::FETCH_ASSOC)) { 
    		$name = $row_events['name'];
    	}
    
        if ($today == $date) {
            $week .= '<td>' . '<div class="today">' . $day . '</div>' . $name;
        } else {
    		$week .= '<td>' . '<div class="day">' . $day . '</div>' . $name;		
        }
        $week .= '</td>';

     

  2. I've been connecting to a database for a number of years now.  The MSSQL server was updated the other day and it can no longer pull the data down.  I connect with PHP PDO ODBC driver.  The connection to the server is good, but nothing is returned.  I can throw the query into my SQL client and bring up the data without a problem.  Any ideas on what I can try?

     

    Here is a sample:

    <?php
     
    $HOSTNAME = '1.1.1.1';
    $DATABASE = 'db';
    $USERNAME = 'user';
    $PASSWORD = 'pass';
     
    try {
    $dbh = new PDO("odbc:Driver={SQL Server};Server=$HOSTNAME;dbname=$DATABASE", "$USERNAME", "$PASSWORD");
    array (PDO::ATTR_PERSISTENT => true);
    } catch (PDOException $e) {
    echo $e->getMessage();
    }
     
    $Barcode = '37782555863';
     
    $sth = $dbh->prepare("
      SELECT 
        LastActivityDate
      FROM
        Customers
      WHERE
        Barcode = :Barcode
    ");
    $sth->bindParam(':Barcode', $Barcode);
    $sth->execute();
     
    while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
      $LastActivityDate = $row['LastActivityDate'];
    }
     
    ?>
     
    <?php echo $LastActivityDate; ?>
    
  3. So I have a search form that has multiple fields.  All the fields are optional, however, I want users to be able to narrow things down by entering some or all if desired.

     

    What I don't know how to do is exclude a field from the search query if nothing is entered.

     

    So the form is setup as:

     

    Subject: select

    Topic: text

    Title: text

    Year: select

    Location: text

    Type: text

     

    Current search query and PHP:

    $subject = $_GET['subject'];
    $topic = $_GET['topic'];
    $title = $_GET['title'];
    $year = $_GET['year'];
    $location = $_GET['location'];
    $type = $_GET['type'];
    
    $sth = $dbh->prepare("
    	SELECT 
    		*
    	FROM
    		periodic
    	WHERE
    		SUBJECT = :subject
    	AND
    		TOPIC = :topic
    	AND
    		TITLE = :title
    	AND
    		YEAR = :year
    	AND
    		LOCATION = :location
    	AND
    		TYPE = :type
    ");
    $sth->bindParam(':subject', $subject);
    $sth->bindParam(':topic', $topic);
    $sth->bindParam(':title', $title);
    $sth->bindParam(':year', $year);
    $sth->bindParam(':location', $location);
    $sth->bindParam(':type', $type);
    $sth->execute();
    

    Obviously the initial query is requiring something in each field with the AND operator and unfortunately, unless the field actually is NULL any field left blank will throw off the results.

     

    Thanks for your pointers.

  4. I have submit buttons and they look identical in IE and Chrome but are rendering differently in Firefox.  It looks like they are adding padding to it, even though I have a CSS reset and explicitly state the padding.

     

    Any ideas on how to force it to look like the IE/Chrome variants?

     

    It typically isn't a problem but when the button is next to a text field it isn't uniform with it like the other browsers.

     

    1pts4o1.png

    .button_submit { 
    margin:0; 
    padding:6px 12px 6px 12px; 
    display:inline-block; 
    border:solid 1px rgba(0,0,0,.05); 
    border-radius:2px; 
    font-family:Arial, Helvetica, sans-serif; 
    font-size:13px;
    color:#FFFFFF; 
    text-align:center; 
    text-decoration:none; 
    vertical-align:baseline;
    cursor:pointer;
    }
    
  5. I apologize if this is not the appropriate forum but it being MySQL related I'll post it here.

     

    I am interested in attempting to get certified in MySQL and am looking at the beginning test:

     

    http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:1Z0-870&p_org_id=&lang=

     

    Has anyone here taken this exam?  I see the exam topics and am wondering how deep and complex it gets or if it's more surface material.  Any examples of what to look for?  Are questions adaptive? 

     

    I have no formal training of MySQL but I've been using it daily for the last 5 years so I am just trying to judge if I stand a shot as it is or if I need to do some hard studying / labs. 

     

    Thanks.

  6. I am trying to generate a random 4 character alphanumeric code.  For some reason my script is sometimes generating a 3 character code, though most the time it is doing a 4 character.  Thanks for your help!

    <?php
    function randomCode() {
        $length = 4;
        $characters = '2345678ABCDEF';
        $code= '';
     
        for ($p = 0; $p < $length; $p++) {
            $code.= $characters[mt_rand(0, strlen($characters))];
        }
     
        return $code;
    }
    echo randomCode($code);
    ?>
    
  7. I guess you could do a couple of approaches.

     

    1. Host the login on your server.  Make myproduct.theircompany.com forward to the login page.

     

    2. Host the login on your server, but on myproduct.theircompany.com use an include for the login form.  Looks like it is hosted on their server but in reality the form itself is included from your server.

     

    3. Store session information in a database and use a custom session save handler.

  8. Running:

     

    Windows Server 2008 R2 64-bit

    Apache 2.4.4 32-bit from Apache Lounge

    PHP 5.4.16 VC9 x86

     

    Apache works fine until I add the following lines at the end of the httpd config file:

     

    LoadModule php5_module "c:/php/php5apache2_4.dll"
    AddHandler application/x-httpd-php .php

    PHPIniDir "C:/php"

     

    The module is located in the path.

     

    I have the Microsoft VS2010 Redistributable x86 installed.

     

    I have C:\PHP; added to the environmental variables in Windows.

     

    Error that occurs when starting the service:

     

    Cannot load C:/PHP/php5apache2_4.dll into server: The application has failed to start because its side-by-side configuration is incorrect.

  9. PHP probably has nothing to do with this, but I just want to make sure.

     

    I get the hostname of computers in our LAN on many occassions.  However, sometimes it is read and displayed differently.  I have not been able to determine what causes it.

     

    Using code:

     

     

    $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
    

     

    I will get the hostname displayed as either: JOHNSPC or JOHNSPC.domain.tld  It will randomly decide which one to display.

     

    I just wanted to make sure there is nothing I can do in PHP configuration to make sure it is consistantly read as one or the other.  I know I can make it read only up to the period, which I may end up having to do.

  10. I need to connect to a database that happens to store the users' passwords in plain text. This is simply to authenticate them then the connection is closed. Is there anything that I can do when connecting, besides the usual validation and sanitization, to make it secure? I am thinking about doing SSL if that is possible but I am out of ideas. I do not have the ability to change their policy on plain text passwords.

  11. I am going to guess this is a problem with javascript, because I can use a typical submit button and have it work.

     

    I am trying to make it so a text link acts as the submit button and have it delete records that are selected via checkbox.

     

    When I click the delete items button it just refreshes the page and removes the check from the box. The record is still there. If I use a submit button it works.

     

    I have for the link:

     

    <a href="#" onclick="document.forms['delete_items'].submit();" title="Delete Items">Delete Items</a>
    

     

    I have for my form:

     

    <form id="delete_items" name="delete_items" method="POST" action="">
    
    <table class="data">
     <tr style="background:#F1F1F1;">
     <td style="width:20px"></td>
     <td>Item</td>
     <td>Owner</td>
     <td style="width:80px">Received</td>
     <td style="width:80px">Returned</td>
     <td style="width:80px">Method</td>
     </tr>
     <?php while ($row_returns = $sth_returns->fetch(PDO::FETCH_ASSOC)) { ?>
     <tr onmouseover="this.bgColor='#EBFAFF';" onmouseout="this.bgColor='#FFFFFF';">
     <td><input type="checkbox" name="<?php echo $row_returns['id'] ?>" value="<?php echo $row_returns['id'] ?>" style="border:none;" /></td>
     <td><?php echo htmlspecialchars($row_returns['item'], ENT_QUOTES, 'UTF-8'); ?></td>
     <td><?php echo htmlspecialchars($row_returns['owner'], ENT_QUOTES, 'UTF-8'); ?></td>
     <td><?php echo htmlspecialchars($row_returns['date_received'], ENT_QUOTES, 'UTF-8'); ?></td>
     <td><?php echo htmlspecialchars($row_returns['date_returned'], ENT_QUOTES, 'UTF-8'); ?></td>
     <td><?php echo htmlspecialchars($row_returns['method'], ENT_QUOTES, 'UTF-8'); ?></td>
     </tr>
     <?php } ?>
    </table>
    
    </form>
    
    
    
    

     

    I have for my PHP script:

     

    if ($_POST['id'] ) {
    foreach($_POST as $id) {
    $sth_delete_item = $dbh_mysql->prepare('
    DELETE
    FROM returns
    WHERE id = :id
    ');
    $sth_delete_item->bindParam(':id', $id);
    $sth_delete_item->execute();
    header("Location: index.php");
    
    }
    }
    
    
    

  12. I have an existing MySQL database with the column:

     

    date_added set as DATETIME

     

    I created a new column called:

     

    date_edited set as DATETIME

     

    What I would like to do is set the DATETIME found in the date_added column into date_edited column for each record without having to do it individually.

     

    Any painless way of doing such a thing?

     

    Thanks!

  13. Javascript doesn't work locally like that as far as I know because of browser restrictions for security, so you can't do anything with local files.

     

    That doesn't really make sense though. All the books I see tell you to install a webserver on your computer using WAMP or XAMP and work from there. All the Youtube tutorials I was trying to do clearly show the user using localhost for development. Those tutorials work fine on my personal PC but not my work computer. I just got to work and am going to nuke my PC.

  14. Okay, so that script works for me when I go to the link.

     

    If I create the script based on the source your provided and try it locally, it does not give the alert. If I upload that script to my live server, it DOES alert. So something is stopping it from working locally. Either WAMP or security settings of some sort. I have tried 3 major browsers and none of them work locally.

     

    It may be worth noting I tried this tutorial and it works on the website, but not locally. It works if I upload it to my live server.

     

    http://api.jquery.com/submit/

  15. Thanks for your advice.

     

    I have tried it both methods suggested and I am still not getting the alert. I have uploaded it to my live web server and am not getting the alert. Here is my updated code:

     

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="jquery/jquery-1.8.2.min.js"></script>
    </head>
    <body>
    <form>
    <input type="text" id="field" />
    <input type="submit" id="submit" value="Submit" />
    </form>
    <script type="text/javascript">
    $(document).ready(function(){	
    $("#submit").click(function()
    {
    alert("A working example.");	
    });
    }):
    </script>
    </body>
    </html>
    

     

    Sorry, the forums seem to lose all my formatting in code tags now.

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