I constantly add store locations to my database but the way I do so is driving me nuts. The code I have pulls the addresses from a text document. I would like to use a simple form to submit the information to the database but I have trouble with database programming. I will list my current code below for information. Since nothing in this world comes free the first person to help out with a working form receives 300 credits.
It does not matter what language you use as long as the job gets done.
Current Code
Simple Code to speed things up:
It does not matter what language you use as long as the job gets done.
Current Code
Code:
$db_server = "localhost";
$db_name = "DBName";
$db_user = "UserName";
$db_pass = "password";
$con = mysql_connect($db_server, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name, $con);
$file_name = "newstations.txt";
$str = file_get_contents($file_name);
$str = str_replace("'", "@", $str);
$stat_arr = explode("\n\n\n", $str);
$stat_count = count($stat_arr);
for ($i = 0; $i < $stat_count; $i++) { $temp_arr = explode("\n", $stat_arr[$i]);
$loc_arr = explode(" ", $temp_arr[2]);
if (count($loc_arr) == 3) { $city = trim($loc_arr[0], ","); $state = $loc_arr[1]; $zip = $loc_arr[2]; } else if (count($loc_arr) == 4) { $city = $loc_arr[0] . " " . trim($loc_arr[1], ","); $state = $loc_arr[2]; $zip = $loc_arr[3]; } mysql_query("INSERT INTO station (name, address, city, state, zip, phone) VALUES ('$temp_arr[0]', '$temp_arr[1]', '$city', '$state', '$zip', '$temp_arr[3]')") or die(mysql_error()); } ?>
Code:
<form action="" method="" >
Name
<input type="text" name="name" value="" id="name" /><br />
Address
<input type="text" name="address" value="" id="address" /><br />
City
<input type="text" name="city" value="" id="city" /><br />
State
<input type="text" name="state" value="" id="state" /><br />
Zip
<input type="text" name="zip" value="" id="zip" /><br />
Phone
<input type="text" name="phone" value="" id="phone" /><br />
<input type="submit" value="Add Station" />
</form>
Last edited: