Need help with collecting CSV data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alibaba
Forum Newbie
Posts: 6
Joined: Fri Oct 21, 2011 7:48 am

Need help with collecting CSV data

Post by alibaba »

Hey Everyone hope all well. I am in need of your php experience.

I will try to explain the best as i can :

I have an html form and inside of that form i have a "select a state" option:

Code: Select all

<select name="State">
<option value="0" selected="selected">Select a State</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
   etc.....
</select>
When the customer selects a state and then clicks the forms submit button, i want them to get taken to a csv file.

Inside of the csv file i have this

Code: Select all

state, ip
AL,67.100.244.74
AK,68.20.131.135
AK,64.134.225.33
etc.......
My goal is to collect the state they choose in the html file and bring it to this csv file. Once it comes to the csv file it chooses an ip address according to the state they choose, then that ip address is sent to me in an email with the rest of the form information.

So an example would be: customer fills out the html form and selects Alabama as a state. they then submit the form and the form comes to the csv file where it sees the state Alabama (AL). it then collects the ip and submits that to my email address along with the rest of the html form information (name,email,etc...). It also needs to randomly choose an ip from Alabama because in the csv file i have Alabama (AL) multiple times, so i just chooses anyone of the Alabama ip's


I hope i am making sense

Thanks for all your help

Ali
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help with collecting CSV data

Post by Celauran »

Might be better to use a database than a CSV file. You could then use a simple query to pull a single IP from the database regardless of how many IPs it contains. It could be made to work with a CSV file, of course, but the larger the file, the longer it's going to take.
alibaba
Forum Newbie
Posts: 6
Joined: Fri Oct 21, 2011 7:48 am

Re: Need help with collecting CSV data

Post by alibaba »

Hi Celauran, thanks for your very fast response.

Could it be done with another php file instead of a csv file or is a database the best option.

Thanks for your time

Ali
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help with collecting CSV data

Post by Celauran »

I suppose it depends on how many IPs you anticipate having. I'd go with a database, but I suppose you could use a config file with a bunch of arrays. How are you adding to the CSV file, and how often?
alibaba
Forum Newbie
Posts: 6
Joined: Fri Oct 21, 2011 7:48 am

Re: Need help with collecting CSV data

Post by alibaba »

Hi Celauran. The CSV file will be updated alot with more ip.

If i wanted to do this via a database how hard is it to do? IS there a lot of code involved.

Any help would be great

Thanks

Ali
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help with collecting CSV data

Post by Celauran »

It should be pretty trivial. phpMyAdmin can import CSV files for you directly.
alibaba
Forum Newbie
Posts: 6
Joined: Fri Oct 21, 2011 7:48 am

Re: Need help with collecting CSV data

Post by alibaba »

Thanks for that. Would you know where i can find some php code to make this all work.

Any help would great

thanks

Ali
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help with collecting CSV data

Post by Celauran »

PHP code to do what, exactly? If you post your existing code, we can help you modify it.
alibaba
Forum Newbie
Posts: 6
Joined: Fri Oct 21, 2011 7:48 am

Re: Need help with collecting CSV data

Post by alibaba »

I don't actually have any php code at the moment. Your idea of database is good. What i am looking for is a place that shows me what php code i need to make this work.

For example
1.how to create the database and import the csv file data into it.
2. What php code do i need to make the form once submitted call upon the database and send me the data

Do you know of a website that explains it at all or even a tutorial

Thanks

Ali
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help with collecting CSV data

Post by Celauran »

There are plenty of tutorials on Google to get you started, but they all teach pretty bad practices. They'll work as a starting off point, though.
Post Reply