ClanKiller.com
https://forums.plasmasky.com/

Offered a small php and mySQL task
https://forums.plasmasky.com/viewtopic.php?f=8&t=1686
Page 1 of 3

Author:  derf [ Tue Mar 07, 2006 3:24 pm ]
Post subject:  Offered a small php and mySQL task

Ive been offered a small task to which i have to accept or reject tomorrow.

In a webpage, imagine a little section where the user fills in his/her contact details to register. Among this section is a field called "Country". The task is to make this field automatically generate the persons current country of residence. I am told, that the IP ranges and the country to which they belong is in a CSV .xls file. I am also told that the best way to do this is to:

1) Insert the CSV into database table (MySQL).
2) Use php to get that country name onto the website field.

Considering that i have never touched php and MySQL (But have done some Oracle SQL)...How in the seven hells can i start?

Author:  Satis [ Tue Mar 07, 2006 3:48 pm ]
Post subject: 

the basic tasks aren't hard.

1. Grab user's ip address.
2. Query database.
3. Fill in country options

actually writing the code is a different story, of course.

Author:  ElevenBravo [ Tue Mar 07, 2006 4:27 pm ]
Post subject: 

Well, since I have NEVER seen that done on ANY webpage before, it might be harder than you think.

Any webpage , big and small, I have ever been to where I have had to fill in my country I have always had to do it manually. Im just pointing out that if the big companys dont do it then there is a reason.

Author:  Mole [ Tue Mar 07, 2006 5:17 pm ]
Post subject: 

I've not seen it done like you need it doing - but google does it, and so do hundreds of other sites. They redirect you to the UK/USA/Korean/Whatever site depending on your IP.

So it should be doable.

Author:  derf [ Tue Mar 07, 2006 5:38 pm ]
Post subject: 

I think your all missing the point. My bad.

I can get the code, thats easy. I meant, how do i actually start up all the programs i need on the screen and start pasting code?

Author:  Satis [ Tue Mar 07, 2006 6:08 pm ]
Post subject: 

wtf? What programs? I code using notepad++ now. Or are you talking about Apache/PHP/MySQL? If the latter, you should be able to find installation out there that do all 3 for you. Personally I like installing them on my own, but if you've never done it you'll probably want to avoid that potential frustration.

Also, you doing this in PHP 5.0 or 4.0? Makes a difference.

Author:  Rinox [ Tue Mar 07, 2006 6:46 pm ]
Post subject: 

ElevenBravo The Great wrote:
Well, since I have NEVER seen that done on ANY webpage before, it might be harder than you think.

Any webpage , big and small, I have ever been to where I have had to fill in my country I have always had to do it manually. Im just pointing out that if the big companys dont do it then there is a reason.



Just to add to the discussion: yeah, by and large I always had to fill in my country myself, but it seems that porn spam ads are great at finding "hot girls" from my neighbourhood, like from a town or two away. (and I live in the middle of nowhere :) )

Either teh spam for teh win, or I happen to live an area overpopulated with unbelieveably hot girls who seem to be unable to find a date offline. I'm thinking it's the former. :wink:

Author:  derf [ Tue Mar 07, 2006 7:59 pm ]
Post subject: 

Okay, im starting from zero now. Ive installed mySQL and im currently installing php v5.somethng.

Mail configuration (wizard) starts during the install.

"Enter address of your SMTP server."

What is this, and why do i need to set it up?

"Enter 'from' address".

Again, how and why?

Anyway, i hit "forward" and specified "Apache".

It said something about "the software for [verb] Apache has not been written yet, you gotta do this manually."

Whats that about?

So, apparently it finishes successfully. Both are on my PC now, whether php works or not, i dont know.

So there, lets say i have some concept code infront of me, how do i code it? Do i embed it into the HTML somehow and upload the php and MySQL scripts?

Oh, and do you think this job could be done in 5 hours? (with no starting knowledge)?

Author:  Pig [ Tue Mar 07, 2006 8:02 pm ]
Post subject: 

For the most part, IP tables are pretty accurate. Some ISP's are worse than others.

In order to make this work, the page needs to have PHP installed (duh), and the page needs to either have a .php extension, or be set up to parse the page extension with PHP (add handler in Apache, for instance). that will make sure your code will run.

The php code to look up the IP is pretty easy. Honestly, if they have the IP in a CSV, it would be easier to work with that than mysql. It would also be more reliable. Once you have the country, you can either write the form field with the value attribute set to the country, or use PHP to write a javascript snippet to populate it.

Sitepoint.com has some good php articles for getting started. If you have a decent amount of time, you should be able to figure it out. IF they want one or two day turn around, i wouldn't take it. Not if you don't know any PHP.

I google around, but everything was way overkill for what you need.

Author:  Pig [ Tue Mar 07, 2006 8:03 pm ]
Post subject: 

I wouldn't bother setting up your own server. Just get them to give you FTP and MySQL access, and then set up a test directory to muck around in. Don't do anything to the real page till you get it right.

Author:  derf [ Tue Mar 07, 2006 8:07 pm ]
Post subject: 

Right, that'll save some hassle.

Author:  Pig [ Tue Mar 07, 2006 8:08 pm ]
Post subject: 

Doh, tripple post! Sorry.

To write code, you just put <?php ?> around your code on the web page. eg:

Code:
<html>
<body>
some text
<?php
echo( str_repeat('x',500) );
?>
</body>
</html>

I wouldn't try it with just 5 hours, starting cold.


*fixed the code example

Author:  Pig [ Tue Mar 07, 2006 8:13 pm ]
Post subject: 

Fucking bullshit. Haven't these phpbb assholes heard of htmlspecialschars()?

there, finally!

Author:  derf [ Tue Mar 07, 2006 8:15 pm ]
Post subject: 

Okay, ive seen the HTML source of the page in question, and it seems he's already got php working on there.

Heres, the bit (i assume):

Code:
      function SendRegistration(toprick)
      {
//         document.registration_form.submit();
         fname      = document.getElementById('fname').value;
         lname      = document.getElementById('lname').value;
         username   = document.getElementById('username').value;
         email      = document.getElementById('email').value;
         company      = document.getElementById('company').value;
         country      = document.getElementById('country').value;
         website      = document.getElementById('website').value;
         phone      = document.getElementById('phone').value;

         url        = 'scriptlets/register.php?' + 'fname=' + fname + '&lname=' + lname + '&username=' + username + '&email=' + email + '&country=' + country + '&company=' + company + '&phone=' + phone + '&website=' + website;
//         alert(url);
         makeRequest(url);

Author:  derf [ Tue Mar 07, 2006 8:16 pm ]
Post subject: 

Pig wrote:
Fucking bullshit. Haven't these phpbb assholes heard of htmlspecialschars()?

there, finally!


:o

Page 1 of 3 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/