Jump to content

matmunn14

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Posts posted by matmunn14

  1. I've been trying to write an application that can connect to a database using Ruby and wxRuby.

    When I click a button I want the program to connect to a MySQL database (I'm using DBI), insert some data and then disconnect but so far I am not having any luck. Also, I'm on Windows.

     

    Here's the code that handles the connection:

    evt_button(22) { |event| button_save_clicked(event) } // This code is for the form with the button.
    
      def button_save_clicked(event)
        @sql = DBI.connect("DBI:Mysql:invoicer:localhost", "root", nil)
        @query = "insert into `customers` VALUES (null, '"+@name.get_value+"', '"+@addl1.get_value+"', '"+@addl2.get_value+"', '"+@suburb.get_value+", '"+@pc.get_value+"', '"+@company.get_value+"', '"+@phone.get_value+"', '"+@fax.get_value+"')"
        @sql.do(@query)
        self.destroy
      end
    

     

    Anyone have any ideas? Also I'm kind of new to Ruby so if I'm doing anything silly then please also tell me so I don't keep making the same mistakes.

  2. That would just create a massive table. If 10,000 members read one post then he would need to insert the same piece of data 10,000 times. Now if 10,000 members read 100 posts then that equates to 1,000,000 rows in a table. That seems like a ridiculous amount of data.

     

    This could probably be fixed if he takes your other suggestion and doesn't check against posts that are greater than a timeout period, your example of 30 days.

  3. Optimising code doesn't always end up working out for the greatest. If you are worried about an extra line then why do you use two variables? Surely you could use something like this:

    $controller = $application->get_controller();
    $controller = new $controller($application->get_action());
    

     

    Or why don't you make it so that the constructor function in the class accepts an argument?

    $controller = $application->get_controller($application->get_action());
    

     

    Something like that maybe?

  4. What about looping and each run through of the loop returns one email?

     

    for($i = 0; $i < 30; $i ++) {
        // code to return one email.
    }
    

     

    Then you would need something like an offset:

     

    <a href="email.php?offset=30">Next Page</a>
    

     

    Then you could use this offset variable to choose where to start from in the list of emails.

  5. hi

    $as = 'az';

    for ( $counter = 0; $counter< 3 ; $counter++) {

     

         echo $as.'';

        $as++;

    }

     

    it's good

    but i want to save like that and print

     

    $as = 'az';

    for ( $counter = 0; $counter< 1 ; $counter++) {

     

        $as=$as.'';

        $as++;

    }

    echo $as

     

    why it's doesn't work?????

     

    Because you are resetting the variable $as within the loop.

  6. Add this after you have checked the user + pass are correct.

     

    <?php
    
    $l_in = $row['logged_in'];
    
    if ($l_in == 1){
    echo "Someone is already logged into that account...";
    }else{
    
    $time = time() + 300; //// 5 mins...
    
    mysql_query("UPDATE yourUsersTable SET logged_in = '1' , timeout = '$time' WHERE username = '$username' AND password = '$password' LIMIT 1")or die(mysql_error());
    
    }
    
    ?>
    

     

     

    Then when they logout:

     

    <?php
    $time = time(); //// now...
    
    mysql_query("UPDATE yourUsersTable SET logged_in = '0' , timeout = '$time' WHERE username = '$username'  LIMIT 1")or die(mysql_error());
    
    ?>
    

     

    And in your functions / include script...

     

    
    $time = time();
    
    $query = "SELECT id FROM yourUsersTable WHERE timeout <= '$time' AND logged_in = '1' ORDER BY id";
    $result = mysql_query($query)or die(mysql_error());
    
    while ($row = mysql_fetch_row($result)){
    
    mysql_query("UPDATE yourUsersTable SET logged_in = '0' WHERE id = '$row[0]' LIMIT 1")or die(mysql_error());
    
    }
    

     

     

    Hope it helps...

     

    @justinede: This is the way that ProjectFear meant and the way that I was explaining that checks for user timeout.

  7. If he's using dreamweaver's code view and then writing the line and trying to look at it in the design view it won't work properly. He would have to upload it to a webserver or view it on his local computer if he has a php installation.

  8. As ProjectFear has said, having a copy of php on your local computer saves you heaps of time, saving you from uploading the same file heaps of times trying to debug a file. WampServer is one of the better ones. There's also EasyPHP, Abyss Webserver and XAMPP.

     

    As for editor software theres Notepad++ which is handy or you could use Eclipse but I find that to be a memory hog.

     

    Google is the best place to look for tutorials and there are heaps out there.

  9. you could do

    <?php
    while($row = mysql_fetch_array($result)){
    $img = $row['table_image'];
    $title = $row['table_title'];
    $imgId = $row['table_id'];
    $images[] = $imgId;
    ?>
    

     

    then somewhere along the line you could do:

     

    $images[$_POST['imageid']]['title'] = $_POST['title'];
    

  10. change:

     

    <?php
    	 if ($_SESSION['regsuccess'] = true){
    
    	 $query = "INSERT INTO `accounts` (`login`,`password`, `lastip`, `email`, `flags`) VALUES ('".$_POST['user']."', '".$_POST['pass']."', '".$_SERVER['REMOTE_ADDR']."', '".$_POST['email']"', '".$_POST['type']."')";
    
        mysql_query($query, ACC_NAME);
    mysql_close(ACC_NAME);
    	 }
    ?>
    

     

    to:

     

    <?php
    	 if ($_SESSION['regsuccess'] = true){
    
    	 $query = "INSERT INTO `accounts` (`login`,`password`, `lastip`, `email`, `flags`) VALUES ('".$_POST['user']."', '".$_POST['pass']."', '".$_SERVER['REMOTE_ADDR']."', '".$_POST['email']."', '".$_POST['type']."')";
    
        mysql_query($query, ACC_NAME);
    mysql_close(ACC_NAME);
    	 }
    ?>
    

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