Jump to content

SharkBait

Members
  • Posts

    845
  • Joined

  • Last visited

    Never

Everything posted by SharkBait

  1. This is how I do my headers: [code] $HEADERS = "MINE-Version: 1.0\r\n"; $HEADERS .= "Content-Type: text/html; charset=iso-8859-1\r\n"; $HEADERS .= "To: {$email}\r\n"; $HEADERS .= "From: Website <support@mydomain.com> \r\n"; [/code] Though it sets up for HTML mail messages. But I have the to, from and sometimes CC in the header. Then I do: [code] if (mail(NULL, $SUBJECT, $MESSAGE, $HEADERS)) {    //Msg sent } else {    // Msg not sent } [/code] I also always put { curly braces } around my variables when I have encased strings in double quotes: [code] echo "This is my string it is {$count} characters long"; [/code] Helps me see and troubleshoot variables a bit better
  2. I dont have the exact code but.. There is the ability to read a file with php. You could read from a .html file line for line and not strip out the tags. Then in your email you would have to make sure the email header contains the type for sending HTML msgs. Then just read from the variable you used from reading the file and use that for the body? As for having PHP read a link and pull the info from a link, I dont have knowledge on that.
  3. Something I like to do before sending the mail (for debugging purposes) is I echo all the email info. I echo the headers, the subject, and body. To make sure that everything is properly placed. Do you remember what you added/changed after you were able to succesfully send an email?
  4. I agree with the about about using a WYSISYG editor with PHP. It just shouldn't be done ;) Even with HTML I would not use dreamweaver for. I used dreamweaver in the past but found it not to my liking and just stuck with notepad (back in the day I used simpletext on my mac). Anyway I use Crimson editor for my PHP and it allows me to learn how the innerworkings... work.. I guess I just like to look at code. Its the insides of thing that fancinate me, not the 'icing on the cake' ;)
  5. So you want to get an option someone selects, put it into a variable and then insert that into the database? [code] <form action="form.php" method="post"> <select name="dropdown">   <option value="1">Option 1</option>   <option value="2">Option 2</option>   <option value="3">Option 3</option> </select> <input type="submit" value="submit" name="submit" /> </form> [/code] Now the script side [code] <?php // Check to see if user clicked the submit button if(isset($_POST['submit'])) {   // Get the option the user selected   $option = $_POST['dropdown'];      // Insert the option into the database   // You will also need a database connection setup before this step....   $strqry = "INSERT INTO myTable (id, option) VALUES(null, '{$option}')";   $query = mysql_query($strqry) or die("MYSQL Error: <br />{$strqry} <br />". mysql_error()); } else {     // Display the form to the user     // Insert above HTML here to display the form } ?> [/code] So $option will be 1, 2 or 3 depending on what the user selected in the drop down box when they click on the submit button. Though I am assuming you mean 'menu' as in a drop down menu on a HTML form of course.
  6. If your pulling multiple values from a table you could through the query in a loop like: [code] // Select all rows in the database $get_gear_info = mysql_query("SELECT * FROM gear_ratios"); // Loop through the rows and output them while($row = mysql_fetch_array($get_gear_info)) {    echo "ID {$row['gear_id']} <br />"; } [/code] Then it would output: ID 1 ID 2 ID 3 . . . Through your whole table. You would also retrieve the other fields via $row['whateverfieldnameis']
  7. Where is the begining If statement?
  8. SharkBait

    SQL Joins

    I've never used a join in the sql query. I am thinking that I really need to start doing it ;) If I have two tables and wish to tie them together I would use a join correct? Currently I do the following: [code] SELECT * FROM table1, table2 WHERE table1.id = 3 AND table1.id = table2.id [/code] Would I be able to use a JOIN with that? I guess what I am really trying to do is select values from 3 seperate tables that all have some sort of correleation between them. IE an id field Am I understanding how JOINs work? It mushes multple tables together into sort of a 'pseudo' table?
  9. There are a couple of Free IP2Country databases out there. What it is is a list of all IP addresses registered to countries. You would take the REMOTE_ADDR of someoen visiting your website, convert their IP to the numerical representation of their IP and then cross reference that with the table. I dont have access to my information on the formula for the conversion or the address of one of the free databases.
  10. Take it one set further and use [code] if(isset($_GET['p'])) {   if($_GET['p'] == "register") {     // Do stuff   } } [/code] Check to make sure the url actually has the variable in it else it might not like it depending on how your error reporting is set.
  11. Is there a proper way to use Global Variables in PHP? I have registered_globals turned off in my php.ini file, but isnt there a $_GLOBALS[] or something? I think my issue with this thread: [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=93787&hl=\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...topic=93787&hl=[/a] is the fact that my CSS file does not see the style variable I am setting before I require() or Include() the header.html file an thus not allow me to make CSS additions with PHP on a per page basis. Hopefully this makes sense.. I would hate to have gigantic thousand line CSS pages, and keeping track of them all wouldnt be that easy. I change formattings of div tags etc depending on the content I need to display, so being able to set CSS variables before I call my header.html file (that links to the actual CSS file) would be great.
  12. [!--quoteo(post=378238:date=May 29 2006, 03:48 PM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ May 29 2006, 03:48 PM) [snapback]378238[/snapback][/div][div class=\'quotemain\'][!--quotec--] So even utilizing 3rd party scripts, I will still(throughout my career) get to do plenty with programming, and things like that. [/quote] I do php for work. But that involves maintaining the website and adding new features to it. Though recently we've bought php packages for things like a knowledge base, live chat etc, that would cost more in the long run for me to start from scratch. $50 for a knowledege base that does what we want is less than what I would get paid for if you converted my salary to $/hr :) Same with a live support application. It was a bit more than the knowledge base but its open source so I can modify it if we need changes/fixes etc (the company that created the live chat software vanished) We're also looking into a PHP CRM for our company. Sure I could write one and spend lots of time with it, but then we could buy one another company has already writen and supports for a decent amount of money *shrug* Though I've written our companies shopping cart, and various other web applications with PHP and MySQL and other languages etc. So I guess it depends on if you have time and is your time worth the amount of money? :)
  13. Was it an update to the forums that broke the php code tags? I miss them But I am sure someone is/has been looking into it.
  14. nl2br = New Line 2 Break :) You'll still have to do your text formatting tags like <strong> and such, but at least this way it will read the database entry with cariage returns :)
  15. [!--quoteo(post=378091:date=May 29 2006, 08:39 AM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ May 29 2006, 08:39 AM) [snapback]378091[/snapback][/div][div class=\'quotemain\'][!--quotec--] I am trying to set all my form field values as an array, and test them all for blank spaces at once, but I am unsure how to put them all into an array. I tried [code] <?php $formfields = array("$_POST['firstname']"=>1, "$_POST['lastname']=>2, "$_POST['emailaddress']=>3, "$_POST['verifyemail']"=>4); foreach ($formfields == ''){ print('One of the fields have been left blank, Please go back and correct this'); } ?> [/code] but I got this and line 2, was during the middle of me setting my array. I caught one error, missed some quotations marks but it still gives the same error. [/quote] Try: [code] // Setting the first entry to 1 will set the rest 1..2..3.. etc :) $formfields = array(1=> $_POST['firstname'],  $_POST['lastname'], $_POST['emailaddress'], $_POST['verifyemail']); // Go through each value in the array foreach($formfields as $value) {   if($value == "") {      // Value is blank       echo "{$value} is blank<br />";   } else {      // Value is not blank   } } [/code]
  16. No problem I like helping when I can
  17. Well with your two submit buttons they are named different correct? [code] <input type="submit" value="Subscribe" name="subscribe" /> <input type="submit" value="Unsubscribe" name="unsubscribe" /> [/code] Then you just check to see which one was pressed: [code] if(isset($_POST['subscribe'])) {   // User wants to subscribe so lets create a INSERT INTO query   $strQry = "INSERT INTO tables(blah, blah2, blah3) VALUES(null, '{$blah}', '{$blah2}', '{$blah3}')";   $query = mysql_query($strQry) or die(mysql_error());   // Succsss if not killed.. } elseif (isset($_POST['unsubscribe'])) {     // User wants to unsubscribe, so lets Delete them!    $strQry = "DELETE FROM table WHERE emailaddress = '{$emailaddress'] LIMIT 1";    $strQry = mysql_query($strQry) or die(mysql_error());    // Success if not killed } else {    // Display form to user to fill out } [/code] In the DELETE FROM table statement, I use the LIMIT 1; Which will only delete 1 instance of what it finds (in case there are multiple email address that are the same). If there is more than one of the same address without LIMIT 1 it will delete them all ;)
  18. [!--quoteo(post=377414:date=May 26 2006, 02:35 PM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ May 26 2006, 02:35 PM) [snapback]377414[/snapback][/div][div class=\'quotemain\'][!--quotec--] ok but I don't get it, what's the difference in those 2 validation methods, I was using this one, so I can chain them together in a huge if, ifelse, else construct, that way it runs down the line. I am still confused about the mysql intry. I just do all the validation then below that on the same page do all of my mysql work. IS there a way to store the mysql information in another page, and if I do that on the same page, will it validate it, and then if it passes validation do the database work, or will it do the validation and that at the same time, meaning will it validate and come back that it wasn't filled in correctly and still pop the information in the database. [/quote] The difference between the two methods is not too much. The one I posted checks to see if the $_POST is empty, like yours which is $_POST == "". I do it with all seperate if/else statements because it makes it neater for me to see where my $_POST variables are and what they are doing. Sometimes my validation can get big because to do parsing of the data if its valid in the same part. I usually do my validation and MySQL stuff on the same page. LIke: [code] if(isset($_POST['submit'])) {    // User submitting things get the variables and validate them       // Create MySQL Query and execute it. } else {    // USer has not submitted the form    // Display the form to them so they can fill it out. } [/code] You can make a seperate page handle the MySQL stuff. You can either require() it or just change the action of your HTML form to point to the new page. As for the MySQL query. [code] $strQry = "INSERT INTO table (id, emailaddress, firstname, lastname) VALUES(null, '{$emailaddress}', '{$firstname}', '{$lastname}')"; [/code] $strQry is a string variable to use later when executing the query INSERT INTO table <-- Table is the name of the table you want to put the information into id, emailaddress, firstname, lastname <-- Are the fields within the table null, '{$emailaddress}', '{$firstname}', '{$lastname}' <-- values to put into the fields respectively. null is a blank instance so that the MySQL Table fills it in automatically (I use ID as a unique auto-increment field) for my primary key. Helps search a bit faster $emailaddress is the variable you have gotten from the HTML form ie $_POST['emailaddress'] I always put the variables betewwn curley braces in my MySQL Queries. The single quotes around those variables are to distinguish between fields in the query. Whew I hope this makes somewhat sense.... [code] $query = mysql_query($strQry) or die("MySQL Error: <br /> {$strQry} <br />". mysql_error(); [/code] mysql_query() <--- function to execute the actual MySQL Query. You feed it the $strQry string. or die() <-- If there is something amiss with the query, it will kill (stop) the script. mysql_error() <-- if there is an error it will tell you what the error is "MySQL Error: <br /> {$strQry} <br /> ". mysql_error(); <-- Something I do when something goes wrong. It will print that line. Show you the string(query) you wanted to execute and then tell you what is wrong with it. Makes debugging queries a bit easier. *wipes forehead* Does that help? I can try and explain it a bit more if not :)
  19. When I validate forms with php I tend to do this: [code] if(!empty($_POST['emailaddress'])) {    // set email address varible here } else {   // Email field was left blank } [/code] Then when you want to insert I would do: [code] //Do all validation above this $strQry = "INSERT INTO table (id, emailaddress, firstname, lastname) VALUES (NULL, '{$emailaddress}', '{$firstname}', '{$lastname'])"; $query = mysql_query($strQry) or die("MySQL Error: {$strQry} <br /> ". mysql_error()); // Continue on.... [/code]
  20. Ok, lets see if I can explain this better.... What I am looking to do is figure out a way to create a random code made up of alphanumeric characters. The reason: So customers can enter this unique, generate code into a website for something special ;) I would then have to insert the randomly generated codes into a database so that I can check to see if its been used or not used etc. The code should less than 10 characters. I am just unsure how I should tackle this. I thought of a hash or sort, but can I make a hash for 10 characters or less? Perhaps some sort of Algorithm so that when they enter their code I can check to see if it is valid, and then I can check to see if its already used (as in already in the database) Kind of like how credticard seeds work. Any thoughts/advice is grealy appreicated :)
  21. To me.. Classes are commonly reused bits of code :) You can also share classes among people (as long as they are written properly) Thats what I always thought them to be anyway... I need to use them more often.
  22. [code] $ip = $_SERVER['REMOTE_ADDR']; if($ip == "123.123.123.123" || $ip == "213.213.213.213") {   // YOUR BANNED } else {   // YOUR NOT BANNED } [/code] Slight variation, try that :)
  23. Book I used that had a basic CMS with even a section for uploading images was: Visual QuickPro Guide: PHP and MySQL for Dynamic Websites Author: Larry Ullman ISBN: 0-321-18648-6 I loved it, I wish more programming books were layed out like this.
  24. [!--quoteo(post=375379:date=May 19 2006, 03:18 PM:name=Andy MacDonald)--][div class=\'quotetop\']QUOTE(Andy MacDonald @ May 19 2006, 03:18 PM) [snapback]375379[/snapback][/div][div class=\'quotemain\'][!--quotec--] err, the only things that are in the admin section is 4 links. add artist, add album, add song, add chart. so i would imagine its somewhere else? sorry to be a pain. [/quote] If there is no way of changing the admin password then you'll have to find out if there is a password for the database that stores if, if that is how it is done. Like Purple said... if its a custom built script there is no way we'll be able to help you.
×
×
  • 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.