Jump to content

MFHJoe

Members
  • Posts

    91
  • Joined

  • Last visited

    Never

Everything posted by MFHJoe

  1. 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. Sorry mate I really don't understand the problem. Could you elaborate?
  6. 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" ); ?>
  7. <?php $str = "house, cup, cup, house, place, smile, cup, house, place"; $arr = explode(', ', $str); $arr = array_unique($arr); $val = implode(', ', $arr); echo $val; ?>
  8. 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.
  9. Yes, that could be very possible actually. Especially if a similar code works for you on another site.
  10. Ruby on Rails is looking pretty good for that kind of thing too. But PHP is much more widely supported at the minute. 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). 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). 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). 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). 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.
  11. 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.
  12. EDIT: Nhoj got there before me 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"); } ?>
  13. 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]
  14. It's no better/worse than any of the other methods really. They're all just used in different situations, but, ultimately, they all do the same thing.
  15. I'd say it's personal preference to be honest. I prefer method 1, and it's probably (marginally) quicker as PHP doesn't have to keep stopping and starting. You could alternatively use the heredoc syntax which was discussed quite a lot here yesterday.
  16. 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.
  17. If you still want to do it like this, look at http://www.phpriot.com/articles/images-in-mysql/
  18. If it's an integer column the second one should be fine.
  19. 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...
  20. [url=http://www.accessify.com/tools-and-wizards/accessibility-tools/pop-up-window-generator/default.php[/url]JavaScript Popup Window Generator . Just use a separate page. You're still going to need to use CSS though.
  21. No problem at all. Trust me mate, it happens to everyone. And it'll happen again .
  22. 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...
  23. 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.
  24. Good luck trying to find one .
  25. <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.