Jump to content

MFHJoe

Members
  • Posts

    91
  • Joined

  • Last visited

    Never

Posts posted by MFHJoe

  1. Is'nt then (Smaty) templating engine and frameworks satisfy the same goal (of seperating presentation ie.HTML+CSS and main PHP code),but in different ways?

    Errrrm, yeah. Smarty is only for templating. Frameworks like CakePHP do have a templating system, but they also do lots of other stuff as well.

  2. Yep, that's it. It's replacing < with < and > with > which is messing with your HTML. You could change BBCode to:

     

    <?php
    //bb code fucntion
    function BBCode($BB){
    				$BBCode = array("&" => "&",
    					"[b]" => "<b>",
    					"[/b]" => "</b>",
    					"[i]" => "<i>",
    					"[/i]" => "</i>",
    					"[u]" => "<u>",
    					"[/u]" => "</u>",
    				$Message = str_replace(array_keys($BBCode), array_values($BBCode), $BB);
    			return $Message;
    								}
    ?>

     

    And that should fix things up.

  3. I think you need quotes on your field names:

     

    $sql="INSERT INTO clients ('client_fname', 'client_lname', 'client_address', 'client_city', 'client_state', 'client_zipcode', 'client_phone', 'client_cphone', 'client_email', 'client_website', 'client_notes') VALUES('$client_fname','$client_lname','$client_address','$client_city','$client_state','$client_zipcode','$client_phone','$client_cphone','$client_email','$client_website','$client_notes')";

  4. Could it be something in the BBCode function? I tried:

     

    $Message = "Hello there\n\nHello there";
    $Output = ucfirst(nl2br(strip_tags($Message)));
    echo $Output;
    ?>

     

    And it seemed to work fine so it's probably the BBCode function. Try getting rid of mysql_real_escape_string (temporarily) and see if that makes a difference - I'm not hopeful about that one though. I'd put my money on BBCode.

  5. Use the HTML:

    <select name="department">
    <option value="Sales">Sales</option>
    <option value="Marketing">Marketing</option>
    <option value="Support">Support</option>
    </select>

     

    Then add to your PHP something like:

     

    <?php
      $email = $_REQUEST['email'] ;
      $message = $_REQUEST['message'] ;
      $department = $_REQUEST['department'];
    
      if($department == 'Sales')
      {
    $sendto = 'sales@yoursite.com';
      }
      elseif($department == 'Marketing')
      {
    $sendto = 'marketing@yoursite.com';
      }
      elseif($department == 'Support')
      {
    $sendto = 'support@yoursite.com';
      }
    
      mail( $sendto, "REQUEST",
        $message, "From: $email" );
      header( "Location: http://www.mysite.com/thankyou.html" );
    ?>

  6. Add a last posted field to the users table in the database with the PHP time() function (or the SQL equivalent). Then just run an if statement on that field before you insert the post into the posts table.

  7. Everything echo'd out ok.  It is possible that the host has some block on folder that will not allow uploads?  I have similar code on another site and it works fine.

    Yes, that could be very possible actually. Especially if a similar code works for you on another site.

  8. I found out that PHP is most preferred language for developing web 2.0 apps

    Ruby on Rails is looking pretty good for that kind of thing too. But PHP is much more widely supported at the minute.

     

    1]what version to start with v4 or v5 ?

    I'd read that v5 introduced OO concepts.so is it ok to directly start with v5 or shall i need to start with v4 and then upgrade myself to v5 once thorough with v4?

    Version 4 is deprecated. Learn version 5. Just make sure the webhost you're going to use is using version 5 as well (sometimes they don't).

     

    2]what learning approach shud be used?

    I started off with 'Programming PHP' book frm O'Reilly.It goes into each fundamentals (like functions,arrays,strings etc) thoroughly with examples limiting to the concept explained.But i am looking for examples which uses multiple concepts together in one ex.

    so guide me tht shall i continue with the same book or use other book for basics? (suggest books in latter case)

    Read the book, if it doesn't help much, then just look on the internet. There's a ridiculous amount of PHP tutorials around (PHPFreaks has some good ones).

     

    3]so far what i learnt is we can use both html & php script in single file.but when i think of developing large apps(being familiar with jsp/servlets) it wud become messy to code both presentation stuff and business logic in single module.so what shud be used for seperation of preso stuff and logic?

    I'd read about template engines (smarty) and mvc kinda frameworks (zend) but i am still confused about difference between them and when to use what? again when i searched,there are many template engines,frameworks to use ,but i;d like to know which is good one,to start with?

    Smarty is a (very good) templating engine. It's used to separate HTML and CSS from PHP which makes things cleaner and is generally better programming practise.

    MVC is a totally different style of coding. It stands for Model-View-Controller, models being the main code, views being the user interface and controllers being the code that interprets what the user is inputting. There's loads of books/online tutorials about MVC, and it's a really good thing to learn if you have the time (I can see programming in the future relying heavily on MVC).

     

    3]4]suggest the organised way of learning php

    As i said,i've come across lot of information about php like -template engines -frameworks -PHP extensions PEAR -AJAX programming with PHP,etc. so i am completely confused what to start with ,i cant learn everything at same time though i feel like doing it,as there must be dependency (which i am now unaware of) to learn something which would requre knowledge of other things .

     

    so please suggest me what to start with then when i shud be learning (ie.sequence) things like

    -template engines -frameworks -mysql connections/apps -PHP extensions PEAR -AJAX programming with PHP,etc.

    Start with the basics. Forget all about templating engines, frameworks, PEAR, etc. Learn about arrays, different variable types, etc. Then move on to mysql connections. Depending on how much programming you've done in the past it may take a while to get past the first few steps but once you've done that you'll be flying (PHP is like that).

     

    5]lastly suggest me good resource for learning php (websites/links/books/pdf's/preso's/ebooks)

    php.net is your friend. If you ever need to know how a function works, it'll tell you (in great detail) over there. PHPFreaks has some useful tutorials that you should read. So does W3Schools. Some other people will definitely have some good resources for you as well.

     

     

  9. You don't have to type echo each line mate. Just do one. They can span multiple lines:

     

    echo "<div class='admin-property-box'>\n
    <h1>$row[name]</h1><div style='clear:both'>&nbsp</div>\n
    <form action='$_SERVER[REQUEST_URI]' enctype='multipart/form-data' method='POST'>\n
    <label for='name'>Property Name:</label> <input type='text' name='name' value=''><br />\n
    <label for='name'>Price:</label> <input type='text' name='price' value=''><br />\n
    <label for='date'>Date:</label>\n";
    
    @include "form-date.inc";
    
    echo "<br />
    <label for='description'>Description:</label>\n
    <textarea rows='5' cols='50' name='description'>\n
    $row[description]\n
    </textarea><br />\n
    <br />Location:<br />\n";

     

    Works just as well.

  10. EDIT: Nhoj got there before me :P

     

    It'd be better doing it with the code below. Nhoj's would work well, unless the user happened to have some weird characters in their password - those characters would be taken out by stripslashes() and mysql_real_escape_string() and the user wouldn't be able to login, even though he was using the password he signed up with.

     

    I've commented the bits I've changed. The code below should work.

     

    <?php
    $host="xxxx"; 
    $username="xxxx"; 
    $password="xxxx1";
    $db_name="xxxx";
    $tbl_name="xxxx";
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    // username and password sent from form 
    $myusername=$_POST['UID']; 
    
    // Encrypt the line below so it may match what's in the database
    $mypassword=md5($_POST['password']);
    
    // To protect MySQL injection
    $myusername = stripslashes($myusername);
    $myusername = mysql_real_escape_string($myusername);
    
    // $mypassword = stripslashes($mypassword); You don't need to stripslashes, it's already md5() encoded so it's safe
    // $mypassword = mysql_real_escape_string($mypassword); Again, no need. It's already md5() so it's safe.
    
    $sql="SELECT * FROM $tbl_name WHERE UID='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);
    
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row
    
    if($count==1){
    // Register $myusername, $mypassword, set cookie and redirect to file
    session_register("UID");
    session_register("password"); 
    header("location:resources.php");
    }
    else {
    header("location:loginerror.html");
    }
    ?>

  11. No need to bump the thread after 1 minute. Anyway, just make a form that looks something like:

     

    <form enctype="multipart/form-data" action="upload.php" method="post">
    Upload File: <input name="file" type="file" /><br />
    <input type="submit" name="submitfile" />
    </form[code]
    
    Note the enctype - it's very important. Once the user submits the form the file gets uploaded to a temporary place on the server. You can access it with $_FILES['file']['tmp_name']. You need to move it to another location on your server (eg. D:\users\uploaded_files) using the move_uploaded_file() function.

    [/code]

  12. When you say ten second countdown, do you mean you visually want it to count down on the screen? Because that's probably better done with JavaScript. If you just mean you want PHP to wait 10 seconds before doing something, try http://php.net/sleep. It doesn't come without it's problems though, I'd recommend you read the comments at the bottom of the php.net page.

  13. Sessions are pretty safe. They only last as long as the client's browser is open though. So if a user shuts down their computer for example, the session is gone. Which is why most websites make use of a mix of sessions and cookies.

    I can't help you with the cookie problem though, seems strange...

  14. As far as I know, there's no way that's completely cross browser. Most scripts seem to work for Internet Explorer but the other browsers don't allow you to do it.

     

    You could just tell users how to do it instead...

  15. EDIT:

    Sorry, one more: You need a semicolon at the end of this line:

    echo '<img src="/cerebra/images/'.$row['id'].'.jpg" width="60" height="75" border="2px" bordercolor="#415582"'

     

    You missed that one ;). That should hopefully fix it. Try that.

     

    And your code's fine mate, I'm probably confusing it even more to be honest.

  16. <input type="checkbox" name="check" />

     

    Is the HTML for making a checkbox. Put this in your form.

     

    To see if someone has checked it or not, in your form processing section, use:

     

    if(isset($_POST['check']))
    {
        // The checkbox has been checked. Do something here.
    }
    

     

    So altogether, your code may look something like this:

     

    <?php
    if (isset($_POST['email']))
    //if "email" is filled out, send email
      {
      //send email
      $email = $_POST['email'] ; 
      $subject = $_POST['subject'] ;
      $message = $_POST['message'] ;
      if(isset($_POST['check']))
      {
        $message .= ' The user checked the checkbox.';
      }
      mail("someone@example.com", "Subject: $subject",
      $message, "From: $email" );
      echo "Thank you for using our mail form";
      }
    else
    //if "email" is not filled out, display the form
      {
      echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>
      Email: <input name='email' type='text' /><br />
      Subject: <input name='subject' type='text' /><br />
      Message:<br />
      <textarea name='message' rows='15' cols='40'>
      </textarea><br />
      Checkbox: <input type="checkbox" name="check" /><br />
      <input type='submit' />
      </form>";
      }
    ?>
    
    </body>
    </html>

     

    The bit inside the if statement uses .= to add a sentence to the end of $message.

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