• Upload Photo Display With PHP & MySQL

      0 comments

    A client was looking for a CMS system for the site that I build for him. Part of this was to give my client the ability to upload pictures along with a descriptions of the cars that they are selling. The coding that I found earlier for this would upload a picture but would not carry along a description with it as well. So I had a thought, why can’t I upload a file to a folder along with uploading the file name and a description to a database and then reflect that back to a site using PHP.

    Here is what I came up with:

    1. First thing you will need to do is to set up your database with the tables that will reflect the form. Next create a new page called form.html adn set up your form giving it the action “add.php”. Then you will need to set up a folder in the directory that this file will be save in either locally or on your server’s file. This code will upload the picture to the above folder.

    <?php

    //This is the directory where images will be saved
    $target = “uploads/”;
    $target = $target . basename( $_FILES['uploadedfile']['name']);

    2. Next you will need the code to upload information to your database. In this example, I am using a MySQL database:

    //This gets all the other information from the form
    $name=$_POST['name'];
    $model=$_POST['model'];
    $year=$_POST['year'];
    $odometer=$_POST['odometer'];
    $price=$_POST['price'];
    $pic=($_FILES['uploadedfile']['name']);
    $description=$_POST['description'];

    mysql_connect(“www.mydatabase.com, “database name”, “password”) or die(mysql_error()) ;
    mysql_select_db(“database”) or die(mysql_error()) ;

    //Writes the information to the database
    mysql_query(“INSERT INTO `sale` VALUES (‘$name’, ‘$model’, ‘$year’, ‘$odometer’, ‘$price’, ‘$pic’, ‘$description’)”) ;

    3. Now the above will file this information on your database. This code has will reflect an error if the file did not go to the file on your server. Now for the rest of the code to send the photo to the file:

    //Writes the photo to the server
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target))
    {

    //Tells you if its all ok
    echo “The file “. basename( $_FILES['uploadedfile']['name']). ” has been uploaded, and your information has been added to the directory”;
    }
    else {

    //Gives and error if its not
    echo “Sorry, there was a problem uploading your file.”;
    }
    ?>

    4. Save this file as add.php

    5. Now here is the code for the display of what you just uploaded:

    <?php
    mysql_connect(“www.mydatabase.com, “database name”, “password”) or die(mysql_error()) ;
    $data = mysql_query(“SELECT * FROM your table”) or die(mysql_error());?>

    <?php $info = mysql_fetch_array( $data ); ?>

    <?php do { ?>
    <table width=”500″ border=”1″ cellspacing=”0″ cellpadding=”0″ align=”center”>
    <tr>
    <td>Photo</td>
    <td>Make</td>
    <td>Model</td>
    <td>Year</td>
    <td>Odometer</td>
    <td>Price</td>
    <td>Description</td>
    </tr>
    <tr>
    <td><img src=”<?php echo “http://www.yourwebsite.com/uploads/”.$info['photo'] .”"; ?> ” alt=”" name=”" width=”100″ height=”90″ border=”1″ /></td>
    <td><?php echo $info['name']; ?></td>
    <td><?php echo $info['model']; ?></td>
    <td><?php echo $info['year']; ?></td>
    <td><?php echo $info['odometer']; ?></td>
    <td><?php echo $info['price']; ?></td>
    <td><?php echo $info['description']; ?></td>

    </tr>
    </table>
    <?php } while ($info = mysql_fetch_assoc($data)); ?>

    6. Save this as display.php. What I have in this coding is a repeat command that will show everything in the database so you can show all at the same time.

    That should do it. Play with it and see if there are areas that can be improved upon and let me know.

  • Good SEO Articles

      0 comments

    In earlier articles I pointed out that one of the most important points of SEO is time! SEO work is something that takes time to get results. Far too many times I received calls from people that are looking to get their rankings up to #1 in Google and they want it right now. So I explain that it takes time to build up a site to a point where it can do so and they either hang up or don’t return my email or they become a client.

    I have found some recent articles that you could say support my opening statement and here they are:

    http://www.ijpweb.com/100-ways-help-build-traffic/

    http://www.wilsonweb.com/articles/checklist.htm

    http://netvestor.blogspot.com/2007/12/top-underestimated-methods-of-quality.html

    http://www.prlog.org/

    The last one is more a gift to you. This is a site that is an account for press releases as well as a good backlink to your site.

    Just remember that anyone that guarantees that you will be #1 on any of the search engines out there is really a fool. A good SEO will go over how things work with doing SEO work on your site, how they will submit your site to the strongest search engines, set you up with local directories as well as directories with in your business arena, create site maps both for your site and ones that Google, Yahoo and Bing can read as well as setting up your business in the Social Media Marketing tools that will work for you.

  • Upload CSV Excel Files To MySQL

      0 comments

    Recently I had a client that need to upload a 2000 row 13 column excel spreadsheet to a MySQL database. The client is a car broker who basically helps people find specific cars and he also buys luxury cars and sells them via his website.

    Being that his distributor gives him access to his database, we thought it would be a good idea to feature this on his website so we decided to add a search feature to the site so if someone was looking for a specific make of car, the search would bring back his distributor’s inventory of that make and then break it down from there. Sound simple but being that I almost no training when it comes to SQL or MySQL, I had to figure out a way to upload this inventory list to a MySQL database. Of course I tried for days to find a way to do this via Google but came up short until I found a someone who lead me in the right direction. So here is what I figured out!

    First thing is first, what was I working with:

    1. Excel for Mac 2007 version.

    2. phpMyAdmin 3.2.2.1

    3. MySQL 5.4.3 beta version

    4. Running off my local host which really does not matter too much.

    So here is how I went about this:

    1. First step was to establish in MySQL a database and set up the columns of the database. (If you are not up to that stage, feel free to contact me and I can walk you through this!!) Obviously the columns should match the columns in your spreadsheet. Please note, that if you, which you should have, added a column for “id” Primary Key and Auto Increment, you will need to add this to your first column of your spreadsheet and sequentially add the numbers to the column to go along with the number of items in the spreadsheet.
    2. Then in your excel spreadsheet you will want to remove the top line or the column names so you are just showing the data that you want to upload in to the database.
    3. Make sure that all the cells in your spreadsheet are all flushed left. You can not have any arbitrary spacing in this format.
    4. In the column after the last data entry column you are going to want to add “|” in each of the cells to match up with the rows of data. This is going to be used in your SQL upload code as the break for each row.  Your spreadsheet ends at Column “R” then place the “|” in Column “S”.
    5. Save As the file as a CSV. (If you want, you can open this file in a text editor program and you will see the layout of the rows like so (item 1, item 2, item 3, item 4, item 5 | ) This would continue on each row with the ” | ” at the end again to show a stop in the row.
    6. Now go to your MySQL program whether it is with your hosting company or on a local host, usually this will be a phpMyAdmin format.
    7. Go in to the new database and then select “import” tab but make sure you have selected the database that you are looking with.
    8. You will notice that at the top of the page you can upload the file that you are looking to use which you should do now.
    9. Once you press the import button will notice now that they format of page has changed a bit. FORMATS OF IMPORTED FILE has changed and added a new option, CSV using LOAD DATA which you are going to want to select.
    10. In the Options you are going to want to check “Replace table data with File”. Then skip down to the next section.
    11. There should be 4 short boxes and then 1 long one. In the first box, “Field terminated by: put in a coma “,” then delete what is in the next 2 boxes.
    12. The 4th box should read the Lines Terminated by and you are going to put a “|” in this box. Basically what you are doing is telling SQL that you are loading information in to the fields of the existing database and the break of each item is a “,” and break of each line is a “|”.
    13. Now delete what ever is in the long box and hit submit.

    As long as you have matched up your columns with your database columns this will work. It is probably a bit unconventional but at the same it worked for what I was doing and it should work for you.

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

  • Google Caffeine?

      0 comments

    google-logoI read a great article this morning about Google Caffeine. When I first saw this I thought that Starbucks and Google got together and made up a new drink for us web designers that would make it so we did not need to sleep any more so we can spend more of our time designing and less time sleeping! Well I was wrong about that.

    Google Caffeine is a new search engine network that Google is going to be launching after the first of the year. I would suggest that you read the article yourself for more information about what Google is doing.

    A few key points that I saw in this article that is very important for all of us. First was the point about when Google got started in 1998. One of their key ideas was to make it easier for small and medium sized companies to be able to be found in the search engines. At that point, the bigger companies with what seems like a bottomless pit of money for advertising were basically able to buy their way to the top which is still the same today but Google set up their search engine to rank sites based on their keywords, description, title, content, hits, etc, etc! One thing that Google did that made it easier for the big business to be able to jack up their page ranking was with back links. The more back links, the higher the ranking of a site. So of course companies popped up that made programs to build up back links and so the big companies were able to take over the rankings again.

    Well Google Caffeine is going to try and change this by going back to the basics and start to rank sites based on the basics as well as how easily sites load to the browsers and now the amount of social bookmarks a site has. Well what is a social bookmark, this is your links to social media sites like, Facebook, Twitter, Linkedin, Digg, etc. Basically Google has seen the light with regards to the latest web trend, our social media market which really has taken off over the last few years. Hell, you are reading this blog, aren’t you and I have a crap load of links to my and my clients sites so the proof is in the pudding here.

    Unfortunately this concept of Google will be short lived. Social Media Marketing is a hot trend and if you take a good look at the multinational companies, you will see more and more on their sites, print and TV advertising “Follow us on:“.  These companies will start to co-op the social media market which will then give them the edge in the market again within a year or so. You will also see that the social media big boys will really be able to capitalize on this trend which means bigger buck in their pockets and less for the little guys out there. At least for now, all is good and those who are catching up to this social media marketing gravy train will be able to make a few bucks!!

SEO Powered by Platinum SEO from Techblissonline