Jump to content

Truman

Members
  • Posts

    109
  • Joined

  • Last visited

Posts posted by Truman

  1. I'm following a tutorial but unfortunately settings on my end are different then on 1:00:00 in the video. I cannot run code as it says "This server is not connected". There is manage connection option but i don't know what to do from there. Before this I installed mySQL and connected to local server from MySQL command line.

     

  2. When I add element in "Search HTML"  box that I want to find on page and it gives me several results. how can I see those that come after the first one? I don't see arrow or anything like that.

    For ex. when I add "id" for some page it gives me 9 results but I see highlighted only the first one. How to scroll to others?

  3. I intend to make lottery drawing program but first wanted to check the basic random module with a code:

    from random import *
    print(randint(1, 100))

    Instead I receive a comment from cmd that contains output of some other file that I created

    2h6f2ts.jpg

    None of my files is named random.py. I have no idea how is this possible.

  4. 8 hours ago, Ingolme said:

    The problem is likely that you're mixing tabs and spaces. Use either one or the other. Not all editors have the same size tabs which is why your indentation goes wrong when pasting it on the forum. 

    Interesting note, will keep that in my mind. Error message points to line 5 - break.

  5. 4 hours ago, justsomeguy said:

    That else should be lined up with the if, not the for.

    Actually, else is lined up with for in official python tutorial and when I change it to what you suggested nothing changes...

  6. image.thumb.png.ca8283a86a8539bca9d9e85f8eb36d7c.png

    This is how my code actually looks like in notepad++. From some reason forum <> function doesn't paste code with the same indentation.

    Regarding the understanding of the code I understand mod operator but my miscomprehension was due to relation between for and else. Mixed things, now it's clearer.

     

  7. for n in range(2, 10):
        for x in range(2, n):
    	    if n % x == 0:
    		    print(n, 'equals', x, '*', n//x)
    		    break
        else:
    		print(n, 'is a prime number')

    There are two issues here:

    1. TabError: Incosistent use of tabs and spaces in indentation

    2. More importantly I don't understand the logic behind this code that leads to this output:

    Quote
    
    2 is a prime number
    3 is a prime number
    4 equals 2 * 2
    5 is a prime number
    6 equals 2 * 3
    7 is a prime number
    8 equals 2 * 4
    9 equals 3 * 3

     

  8. Hi,

    I'm looking at this piece of code:

    words = ['cat', 'window', 'defenestrate']
    for w in words[:]:     
        if len(w) > 6:         
            words.insert(0, w)  
    words ['defenestrate', 'cat', 'window', 'defenestrate']

    If I understand well it should make copy of the list and add 'defenestrate' into list but I receive a message "tuple object has no attribute instert". This code is a part of a tutorial I'm following and not sure why it doesn't work.

  9. How could I know that the error is on line 3 of another file?

    And this is the code for header.html:

    <?php // Script 1.4 - header.html 
    include('functions.php');
    <!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" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" media="all" href="css/style.css" />
    <title><?php 
    if (defined('TITLE')) {
     print TITLE;
    } else {
     print 'My site of quotes.';
    }
    ?></title>
    </head>
    <body>
     <div id="container">
       <h1>My site of quotes.</h1>
       <br />
       <! -- Begin changeable content. -->
     
    
  10. I wrote a simple code for logout:

    <?php // Script 1.7 - logout.php
    if (isset($_COOKIE['Samuel'])) {
      setcookie('Samuel', FALSE, time()-300);
    }
    define('TITLE', 'Logout');
    include('templates/header.html');
    print '<p>You are now logged out.</p>';
    include('templates/footer.html');
    ?>
    

    but I receive:
    Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\my-site\all\templates\header.html on line 3

     

    This makes no sense to me...

  11. I see the problem. Your code has $FILES rather than $_FILES.

     

    But also the uploads directory must exist, as I mentioned above.

    Actually this '$FILES' was a mistake, when I corrected it worked! I already made uploads directory for this purpose.

     

    I will also take a look on other suggestions that you and your colleagues gave me on this topic.

  12. You forgot a break; after case 6.

     

    You should put print '.</p>'; outside of the switch statement.

     

    If there's no temporary folder then you'll have to set up your server to provide PHP with a temporary folder for uploaded files.

    After making those changes I still receive the same note. I use XAMPP server, can you please shortly explain me how to set it up?

  13. I wrote this correct code:

    <!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" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Upload a File</title>
    </head>
    <body>
    <?php // Script 11.4 - upload_file.php
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
      if (move_uploaded_file($FILES['the_file']['tmp_name'],"../uploads/{$_FILES['the_file']['name']}")) {
        print '<p>Your file has been uploaded.</p>';
      } else {
        print '<p style="color:red;">Your file could not be uploaded because: ';
    	switch($_FILES['the_file']['error']) {
    	case 1:
    	  print 'The file exeeds upload_max_filesize setting in php.ini';
    	  break;
    	case 2:
    	  print 'The file exeeds MAX_FILE_SIZE setting in the HTML form';
    	  break;
    	case 3:
    	  print 'The file was only partially uploaded';
    	  break;
    	case 4:
    	  print 'No file was uploaded.';
    	  break;
    	case 6:
    	  print 'The temporary folder does not exist.';
    	default:
    	  print 'Somethin unforseen happened.';
    	  break;
    	  print '.</p>';
    	}
      }
    }
    ?>
    <form action="upload_file.php" enctype="multipart/form-data" method="post">
     <p>Upload a file using this form: </p>
     <input type="hidden" name="MAX_FILE_SIZE" value="300000" />
     <p><input type="file" name="the_file" /></p>
     <p><input type="submit" name="submit" value="Upload this file" /></p>
    </form>
    </body>
    </html>
    
    

    I ran this code through browser, uploaded a file that I named 'the_file' and I received error 6:

    Your file could not be uploaded because: Something unforseen happened.

     

    Is there something that I'm missing here?

  14. <!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" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Date Menus</title>
    </head>
    <body>
    <?php // Script 10.1 - menus.php 
    function make_date_menus() {
     $months = array(1 => 'January', 'February', 'March', 'Aprile', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
     print '<select name="month">';
      foreach ( $month as $key => $value ) {
       print "\n<option value=\"$key\">$value</option>";
       }
     print '</select>';  
     print '<select name="day">';
      for ($day=0; $day<=31; $day++) {
       print "\n<option value=\"$day\">$day</option>";
      } 
     print '</select>';
     print '<select name="year">
      $start_year = date('Y');
      for ($y = $start_year; $y <= ($start_year + 10); $y++ ) {
       print "\n<option value=\"year\">$y</option>";
       }
     print '</select>';
     } // end of make_date_menus function.
    print '<form action="" method="post">';
    make_date_menus();
    print '</form>';
    ?>
    </body>
    </html>
    

    and the error is:

    Parse error: syntax error, unexpected 'Y' (T_STRING) in C:\xampp\htdocs\my-site\menus.php on line 23

     

    I don't see why 'Y' is an error, I used already existing function...

×
×
  • Create New...