• Upcoming Articles

      0 comments

    I have had a few wild things that I have had to learn for a new site that I am working on so I will be writing a few new articles very soon.

    First is going to be on uploading Excel Spreadsheets to MySQL directly, not using PHP or ASP code to get this done.

    Other is going to be on making a search function for a website using MySQL and PHP. This one will be submitted to Dreamweaver directly because there is a huge mistake on their instructions on how to do this. I found 3 websites that pretty much gave directions on doing this exactly the same and all 3 forgot to include the most fundamental actions in the form that make the search work!

    I will put these up right before the new year as I have a few websites that I am working on right now.

  • Add Pictures With PHP

      0 comments

    I found code that you can use to be able to upload pictures to a MySQL server with PHP. This is useful code to use if you are making a Contact Management System or a back end system for yourself or your client so that they can upload photos to a database which will then be echoed back to your server. I put this together using phpMyAdmin, MySQL and Dreamweaver CS4.

    First thing you need to do is to go in to your phpMyAdmin program. Click the tab SQL and then cut and paste in this text to create the proper database for the php code below:

    CREATE TABLE IF NOT EXISTS `files` (
    `fid` int(11) NOT NULL AUTO_INCREMENT COMMENT ‘unique id’,
    `name` varchar(30) NOT NULL COMMENT ‘file name’,
    `type` varchar(30) NOT NULL COMMENT ‘MIME type’,
    `size` int(11) NOT NULL COMMENT ‘file size’,
    `content` mediumblob NOT NULL COMMENT ‘actual file’,
    `description` varchar(100) NOT NULL,
    PRIMARY KEY (`fid`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COMMENT=’Uploaded files’ AUTO_INCREMENT=7 ;

    Open an html page and save it as “form.html”. Then place in this code between the body tags:

    <form action=”upload.php” method=”post” enctype=”multipart/form-data” name=”uploadform”>
    <input type=”hidden” name=”MAX_FILE_SIZE” value=”350000″>
    <input name=”picture” type=”file” id=”picture” size=”50″>
    <input name=”upload” type=”submit” id=”upload” value=”Upload Picture!”>
    </form>

    Now open a new php page and save it as upload.php making sure you are saving it in the same folder as the form.html.

    <?php require_once(‘your connection‘); ?>

    <?php

    // if something was posted, start the process…
    if(isset($_POST['upload']))
    {

    // define the posted file into variables
    $name = $_FILES['picture']['name'];
    $tmp_name = $_FILES['picture']['tmp_name'];
    $type = $_FILES['picture']['type'];
    $size = $_FILES['picture']['size'];

    // get the width & height of the file (we don’t need the other stuff)
    list($width, $height, $typeb, $attr) = getimagesize($tmp_name);

    // if width is over 600 px or height is over 500 px, kill it
    if($width>600 || $height>500)
    {
    echo $name . “‘s dimensions exceed the 600×500 pixel limit.”;
    echo  “<a href=\”form.php\”>Click here to try again.</a>”;
    die();
    }

    // if the mime type is anything other than what we specify below, kill it
    if(!(
    $type==’image/jpeg’ ||
    $type==’image/png’ ||
    $type==’image/gif’
    )) {
    echo $type .  ” is not an acceptable format.”;
    echo  “<a href=\”form.php\”>Click here to try again.</a>”  ;
    die();
    }

    // if the file size is larger than 350 KB, kill it
    if($size>’350000′) {
    echo $name . ” is over 350KB. Please make it smaller.”;
    echo “<a href=\”form.php\”>Click here to try again. </a>”  ;

    die();
    }
    // if your server has magic quotes turned off, add slashes manually
    if(!get_magic_quotes_gpc()){
    $name = addslashes($name);
    }

    // open up the file and extract the data/content from it
    $extract = fopen($tmp_name, ‘r’);
    $content = fread($extract, $size);
    $content = addslashes($content);
    fclose($extract);  ?>

    <?php  // connect to the database
    include(‘your connection‘); ?>
    <?php
    // the query that will add this to the database
    $addfile = “INSERT INTO files (name, size, type, content, description ) “.
    “VALUES (‘$name’, ‘$size’, ‘$type’, ‘$content’, ‘$description’)”;

    mysql_query($addfile) or die(mysql_error());

    // get the last inserted ID if we’re going to display this image next
    $inserted_fid = mysql_insert_id();

    mysql_close();
    // display the image
    ?>
    <div align=”center”>
    <strong><? echo $name; ?><br>
    </strong><img name=”<? echo $name; ?>” src=”getpicture.php?fid=<? echo $inserted_fid; ?>” alt=”Unable to view image #<? echo $inserted_fid; ?>”>
    <br>
    <a href=”upload.php”>upload more images</a>
    </div>
    <p>
    <?
    // we still have to close the original IF statement. If there was nothing posted, kill the page.
    }else{die(“No uploaded file present”);
    }
    ?>

    Now open a new php file and save it as getpicture.php and drop in this code:

    <?php

    if(isset($_GET['fid']))
    {
    // connect to the database

    include "your connection";

    // query the server for the picture
    $fid = $_GET['fid'];
    $query = “SELECT * FROM files WHERE fid = ’$fid’”;
    $result = mysql_query($query) or die(mysql_error());

    // define results into variables
    $name=mysql_result($result,0,”name”);
    $size=mysql_result($result,0,”size”);
    $type=mysql_result($result,0,”type”);
    $content=mysql_result($result,0,”content”);

    // give our picture the proper headers…otherwise our page will be confused
    header(“Content-Disposition: attachment; filename=$name”);
    header(“Content-length: $size”);
    header(“Content-type: $type”);
    echo $content;

    mysql_close();
    }else{
    die(“No file ID given…”);
    }
    ?>

    Now that should do it for you.  From there you can set this up to work in several different formats but now you have the ability to upload photos and then have them show. Any questions please let me know.

  • PHP Form That Sends You An Email

      1 comment

    When making  a form on a website there are several options of where you want that information to go, either a database or to your email. This would be done with a site that you have a form that gathers information from a client who is requesting more information. For some time now I have been trying to work out how to have both actions, send the data to a database and to my email. This way I have captured the clients information in a database which I can then use to contact them at a later date. Having to go to my email helps me know who is trying to reach me about their website.

    Now I have it set up so that both can happen and here is the php code for it for the form:

    <?php
    } else {
    ?>
    <form action=”test.php” method=”post”>
    <table width=”400″ border=”0″ align=”center” cellspacing=”2″ cellpadding=”0″>
    <tr>
    <td width=”29%”>Your name:</td>
    <td width=”71%”><input name=”name” type=”text” id=”name” size=”32″></td>
    </tr>
    <tr>
    <td>Email address:</td>
    <td><input name=”email” type=”text” id=”email” size=”32″></td>
    </tr>
    <tr>
    <td>Comment:</td>
    <td><textarea name=”comment” cols=”45″ rows=”6″ id=”comment”></textarea></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td align=”left” valign=”top”><input type=”submit” name=”Submit” value=”Send”></td>
    </tr>
    </table>
    </form> ?>

    Here is the code for the email action:

    <?php
    if ($_POST["email"]<>”) {
    $ToEmail = ‘youremail@site.com’;
    $EmailSubject = ‘Site contact form ‘;
    $mailheader = “From: “.$_POST["email"].”\r\n”;
    $mailheader .= “Reply-To: “.$_POST["email"].”\r\n”;
    $mailheader .= “Content-type: text/html; charset=iso-8859-1\r\n”;
    $MESSAGE_BODY = “Name: “.$_POST["name"].”<br>”;
    $MESSAGE_BODY .= “Email: “.$_POST["email"].”<br>”;
    $MESSAGE_BODY .= “Comment: “.nl2br($_POST["comment"]).”<br>”;
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die (“Failure”);
    ?>}

    Couple of points that you need to pay close attention to in the email PHP code is that you need to fill in the $ToEmail variable so that it has your email address that you are sending it to. Also, make sure that the other variable’s strings throughout the form match the tables id’s. For example: $mailheader = “From: “.$_POST["email"].”\r\n”; the area $_POST["email"] is the id for the form which you will have to match with the database row. With my site I have it like this: $mailheader = “From: “.$_POST["txtEmail"].”\r\n”;. The txtEmail represents my row in the table for my database. So make you go through and match this up.

    Very, very important update! You will need to add this hidden field just below the submit but still in the <form></form> area “<input name=”email” type=”hidden” id=”admin@linkedupdesign.com” value=”email” />”. The email will not be sent unless you have this in there. This is the hidden field that tells the <?php?> to work!!  make sure that the value=”email” and the name=”email” stay the same because that is the global $_POST variable name.

    I have this email PHP code set up just about the form but not part of the <form></form>. Reason being is the form action is the recordset to post in to the databse so you don’t want to cross wires per say. These will be two separate action in the form.

    If you have any questions about this please feel free to get in touch with me.

  • Setting Up Testing Server Dreamweaver CS4

      5 comments

    dreamweaver_cs4_150x150

    On several occasions I have tried to set up to a database via Dreamweaver and I would get an error saying that Dreamweaver could not find a proper Testing Server. I have run in to this problem a few times now while working with Dreamweaver CS4 because I keep forgetting to write up what to do to handle it.

    I went on to the Dreamweaver help page and the only thing I can say is that engineers should not write instructions, bahh, if I was smart enough to understand what is said, I could write my own programs like Dreamweaver! I will take this up another day.

    Finally I remembered what I did in the past so here it is:

    This is what you would you would do only after you have set up the site and remote server:

    • SERVER MODEL: PHP MySQL
    • ACCESS: FTP
    • FTP HOST: ftp.site.com
    • HOST DIRECTOR: (leave blank)
    • LOGIN: login
    • PASSWORD: password
    • URL PREFIX: (this usually defaults to “http://ftp.site.com) change to “http://www.site.com”

    This last line is where I usually screw up by keeping the default setting where I then spend the next 100 hours trying to figure this out.

    Do take the note from Dreamweaver’s help page:

    Note: As of Dreamweaver CS4, Dreamweaver no longer installs ASP.NET or JSP server behaviors. If you’re working on ASP.NET or JSP pages, however, Dreamweaver will still support Live Mode, code coloring, and code hinting for those pages. You do not need to select ASP.NET or JSP in the Site Definition dialog box for any of these features to work.


  • Learning PHP

      0 comments

    PHP or as the pro’s know it Processor Hypertext Preprocessor or if you look further in to the history, it simple meant, Personal Home Page!! If you want to see a good example of PHP at work, well, look around your screen, this site is powered by PHP which means that it is powered by databases and PHP language is used to relay information on an HTML page from databases.

    PHP.net is your best bet to find out all of the information about PHP, today I am just updating to mention that I am doing a class on Lynda.com that teaches the basics of PHP. More to come later!!

SEO Powered by Platinum SEO from Techblissonline