Jump to content

Wolphie

Members
  • Posts

    682
  • Joined

  • Last visited

    Never

Posts posted by Wolphie

  1. You first need to get the POST data from the form.

     

    <form action="my_form.php" method="POST">
     <p>Name: <input type="text" name="name" /></p>
     <p>
       <input type="submit" name="submit" value="Go" />
       <input type="submit" name="submit" value="Cancel" />
     </p>
    </form>
    

     

    my_form.php

    <?php
    $action = $_POST['submit'];
    
    if(isset($action)) {
     switch ($action) {
       case 'Go':
         print 'Hello ' . $_POST['name'] . ', you hit ' . $action;
         break;
       case 'Cancel':
        print 'Hello ' . $_POST['name'] . ', you hit ' . $action;
        break;
     }
    }
    ?>
    

       

  2. We're not here to write scripts for you, regardless of whether you're a beginner or not. We will however provide help and assistance if you have/need any help with the code you've written or don't understand. For us to help you, you need to show at leat some effort and commitment to some degree.

     

    papaface provided you with your answer, google is the best place to find what you're looking for. If you really want someone else to write it for you then go to the Freelance forums.

  3. It is possible to return HTML inside a PHP function yes, although I don't see why you would want to return an entire table in PHP. I can understand if you actually wanted to populate a table using PHP.

  4. If you want some advice, use a PHP framework, something of a MVC (Model, View, Controller) architecture. It should help you manage your code, and help seperate large blocks of your code from the initial design. My personal favorite is Zend Framework, or Drupals built-in framework.

  5. This is not true, you don't have to 're-make' the page, you only need to refresh it, unless you use JavaScript, an in which case would allow you to use Ajax to automatically query the script every 5 minutes or something for new images.

     

    A simple example:

     

    <?php
    $dir = dir('images');
    
    while (($file = $dir->read()) !== false) {
     if(($file != '.') || ($file != '..')) {
       print '<img src="' . $file . '" border="0" />';
     }
    }
    
    $dir->close();
    ?> 
    

     

    This is just a very basic example of how to list files in a directory. In order to dynamically resize an image to create the thumbnail, you would have to use GD Library, or ImageMagik.

     

    You could also upload the images into a BLOB on a database, or just store the image paths. The possibilities are endless, it may be tough although it's worth learning!

  6. Etiquette schmetiquette...

     

    Just some basic decency should be enough.

     

    Agreed. It just goes to show how a long and detailed explanation could be out weighed by a short and simple answer. I personally feel a sense of accomplishment also, and try to help as much as I can even when I don't fully understand the code, the explanation, the desired result etc..

  7. <?php
    
    $to = 'test@domain.co.za';
    $email = $_POST['email'];
    $info = $_POST['message']; // this should be the same as the name on the form element
    
    $message = <<<MESSAGE
    <html>
      <head>
        <title>HTML E-mail!</title>
      </head>
      <body>
        <table border="1">
          <tr>
            <td>$info</td>
            <td>This is an HTML e-mail!</td>
            <td>This is an HTML e-mail!</td>
          </tr>
        </table>
      </body>
    </html>
    MESSAGE;
    
    $subject = 'HTML E-mail!';
    
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: ' . $email;
    
    mail($to, $subject, $message, $headers);
    ?>
    

  8. This isn't a failsafe method. A lot of people have HTML formatting switched off for their e-mails, in which case if you were to send a HTML formatted e-mail they would get thoroughly confused. You should provide an option for your users to select which format the e-mail should be in. And in which case, if they make a mistake it's down to them. And you'll then be able to determine which format the e-mail should be sent in, either plain text or HTML.

     

    But back to your original question:

    <?php
    
    $to = 'example@domain.com';
    
    $message = '<html><head><title>HTML E-mail!</title></head><body>This is an HTML e-mail!</body></html>';
    
    $subject = 'HTML E-mail!';
    
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: anotherexample@domain.com';
    
    mail($to, $subject, $message, $headers);
    
    ?>
    

  9. Since you're running a mac, I would first suggest downloading and installing a useful IDE (intergrated development enviroment). For the mac I use either Xcode development tools (download from the apple developer connection website free, version 3.0 for OS X 10.5) or TextMate, which isn't free although it's better than Xcode in my opinion. With these you'll be able to create a range of different files.

     

    But back to your original question, it isn't difficult. For example, when you open say notepad on windows and type something and then save it. It'll ask you to enter a name to save it as, and it'll have a .txt extension. You just change this .txt file extension to .php.

     

    The best resource for learning PHP would be PHP.net

     

     

    He has a point though, if you don't know how to do something in which a job requires then you don't need that job. Epically since there is probably vary highly qualified PHP programmers that need work **cough**me**

     

    How is that relevant? If you're going to criticise people, at least offer a solution rather than just being an a** about it. At the end of the day, we were all beginners at some stage. None of us knew how to do any of this, until we put in the effort to learn and asked for guidance from more experienced people along the way.

  10. You won't be able to prevent users from directly downloading videos unless you use a password protected directory or store it outside the web root as the previous posts have stated. Though generally, when you stream videos they're stored in the cache anyway.

  11. Have you tried to echo the parameters to see if the variables are even getting set before calling the function?

     

    <?php
    function updateContent($pgname, $content, $id) {
     
     echo $pagname . '<br />';
     echo $content . '<br />';
     echo $id;
    
     $db = new sql();
     // Always add error handling
     $result = $db->sql_query("UPDATE `content` SET `pagename` = '$pgname', `content` = '$content' WHERE `id` = '$id'") or trigger_error(mysql_error()); 
    
     if($result) 
       return $result;
     else
       return false;
    
    }
    
    // Then when calling your function use a condition with error handling
    
    if(updateContent($_POST['name'], $_POST['rte1'], $_GET['update'])) {
     echo 'Updating...';
    else
     echo 'Could not update!';
    
    ?>
    

  12. You're not being very clear, but it's because you're still using parentheses.

    Here's an example of how it should be done.

     

    <?php
    
    $myVar1 = 1; // An integer
    $myVar2 = 1; // A string
    
    if($myVar1 == 1) {
     echo 'My variable is an integer, Wahoo!';
    }
    
    if($myVar2 == '1') {
     echo 'My variable is a string, Wahoo!';
    }
    ?>
    

     

    They'll both display the message regardless of ' ' because PHP is a loosely typed language unlike C++ and stuff.

     

    Yes, PHP is a loosely typed language. However, declaring and comparing variables should, in my opinion be done the way it's supposed to be done. In my experience, it makes debugging much easier, and should reduce the chances of problems such as declaration issues, syntactical/parse errors from occurring. But again, that's just my opinion. I'm pretty strict when it comes to writing clean and easy to read code.

  13. You're not being very clear, but it's because you're still using parentheses.

    Here's an example of how it should be done.

     

    <?php
    
    $myVar1 = 1; // An integer
    $myVar2 = '1'; // A string
    
    if($myVar1 == 1) {
     echo 'My variable is an integer, Wahoo!';
    }
    
    if($myVar2 == '1') {
     echo 'My variable is a string, Wahoo!';
    }
    ?>
    

     

    Also stick error handling on.

     

    error_reporting(E_ALL);

     

    Also use mysql_error() for your queries.

     

    $query = mysql_query("query...") or trigger_error(mysql_error());
    

  14. Or you could alternatively use PHP's built in templating engine.

     

    <html>
      <head>
        <title><?=$website['title'];?></title>
      </head>
      <body>
        <? if($online) : ?>
          <!--Your regular page here.-->
        <? else : ?>
          <!--Website offline display message.-->
        <? endif; ?>
      </body>
    </html>
    

     

    Personally I don't mind using shorthand PHP tags when it's inside a HTML document. I don't ever declare a PHP document with them though. Also, it doesn't comply with PEAR coding standards (at least I don't think so).

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