Location: PHPKode > scripts > Php AddressBook 2 > php-addressbook-2/add.php
<?
if ( isset($save) ) { 
if($firstname == '') {
echo "No Data Entered<br><br>
<input type=button value=\"Back\" onClick=\"parent.location='index2.php?title=add'\" tabindex=\"1\">";
exit;
}

if(!$profile == '') {
include_once("upload-file.php");
$profileimg = $randName . '.' . $ext;
}

// this line of code will allow php to convert the hidden new line elements \n with <br>
	$comment_content = str_replace("\n","\n<br>",$_POST['comments']);
	
	$firstname_escape = mysql_real_escape_string($_POST['firstname']);
	$lastname_escape = mysql_real_escape_string($_POST['lastname']);
	
////////////////////////////////////////////////////////////////////////////	
// This will connect to google using a hard Address and will retun Geocodes
////////////////////////////////////////////////////////////////////////////	
   // Desired address
   $googleAddress = "http://maps.google.com/maps/geo?q=".urlencode($address) .'+'. urlencode($city) .'+'. urlencode($province).'+'. urlencode($country)."&output=xml&key=ABQIAAAAszLikyuY4pfiEpirkGCftRRuq_0xIe31RPQ27lsUiOZikg6IYxS0EY7fSKFxRPl31x6v4x8fdHtUFw";

   // Retrieve the URL contents
   $googlePage = file_get_contents($googleAddress);

   // Parse the returned XML file
   $xml = new SimpleXMLElement($googlePage);

   // Parse the coordinate string
list($lng, $lat, $altitude) = explode(",", 
     $xml->Response->Placemark->Point->coordinates);

// Output the coordinates
//echo "Longitude: $longitude, Latitude: $latitude";
	
// Inster profile information
mysql_query("INSERT INTO addressbook (firstname, lastname, address, suite, postalcode, city, province, country, home, mobile, work, work2, fax, email, email2, email3, yahoo, msn, icq, website, profile, comments, jabber, gtalk, aim, skype, gid, lat, lng) VALUES('$firstname_escape', '$lastname_escape', '$address', '$suite', '$postalcode', '$city', '$province', '$country', '$home', '$mobile', '$work', '$work2', '$fax', '$email', '$email2', '$email3', '$yahoo', '$msn', '$icq', '$website', '$profileimg', '$comment_content', '$jabber', '$gtalk', '$aim', '$skype', '$gid', '$lat', '$lng') ")
or die(mysql_error());
 
echo "Data Saved!<br />";
// Close DB connection
}
 ?>

<div class="barCenter">
  <div class="note"> Fields marked with a <span class="required">*</span> are required.</div>
</div>
<form method="post" action="?title=add" enctype="multipart/form-data">
  <fieldset>
  <h1>Personal Info:</h1>
  <hr />
  <dl>
    <div class="barLeft">
      <dt>
        <label for="firstname">First Name: <span class="required">*</span></label>
      </dt>
      <dd>
        <input type="text" name="firstname" id="firstname" value='' tabindex="1"/>
      </dd>
      <dt>
        <label for="lastname">Last Name:</label>
      </dt>
      <dd>
        <input type="text" name="lastname" id="lastname" tabindex="2"/>
      </dd>
      <dt>
        <label for="broupe">Groupe:</label>
      </dt>
      <dd>
        <?
echo "
<select name=\"gid\">
<option value='1'>Select a Groupe</option>";
// Connect to the groups table to get data
 # setup SQL statement
    $sql = "SELECT * FROM groups ORDER BY groups ASC";

    # execute SQL statement
    $grs = mysql_query($sql, $cid);
    if (mysql_error()) { print "Database Error: $sql " . mysql_error(); }

    # execute SQL statement
$grs = mysql_query($sql) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($grs);
			
for($i = 0; $i < $numofrows; $i++) {
    $row = mysql_fetch_array($grs); //get a row from our result set
	    $gid = $row["gid"];
		$groups = $row["groups"];
			
		# Output
		echo "<option value='$gid'>$groups</option>";
		
}
echo "
</select>
";
// Close DB connection
?>
      </dd>
      <dt>
        <label for="address">Address:</label>
      </dt>
      <dd>
        <input type="text" name="address" id="address" tabindex="3"/>
      </dd>
	  <dt>
        <label for="address">suite:</label>
      </dt>
      <dd>
        <input type="text" name="suite" id="suite" tabindex="3"/>
      </dd>
      <dt>
        <label for="postalcode">Postal/Zip Code:</label>
      </dt>
      <dd>
        <input type="text" name="postalcode" id="postalcode" tabindex="3"/>
      </dd>
      <dt>
        <label for="city">City:</label>
      </dt>
      <dd>
        <input type="text" name="city" id="city" tabindex="5"/>
      </dd>
      <dt>
        <label for="province">Province/State:</label>
      </dt>
      <dd>
        <input type="text" name="province" id="province" tabindex="6"/>
      </dd>
      <dt>
        <label for="country">Country:</label>
      </dt>
      <dd>
        <input type="text" name="country" id="country" tabindex="7"/>
      </dd>
      <dt>
        <label for="website">Website:</label>
      </dt>
      <dd>
        <input type="text" name="website" id="website" tabindex="8" value="http://"/>
      </dd>
    </div>
    <div class="barRight">
      <dt>
        <label for="comments">Comments:</label>
      </dt>
      <dt>
        <textarea name="comments" id="comments" wrap="HARD"  cols="30" rows="10" tabindex="9"></textarea>
      </dt>
      <dt>
        <label for="profile">Profile:</label>
      </dt>
      <dd>
        <input type="file" name="profile" id="profile" tabindex="10"  size="10">
      </dd>
      Images must be in JPG format. </div>
  </dl>
  <dl>
    <div class="clearfix"></div>
    <h1>Contact Information:</h1>
    <hr />
    <div class="barLeft">
      <dt>
        <label for="home">Home:</label>
      </dt>
      <dd>
        <input type="text" name="home" id="home" tabindex="11"/>
      </dd>
      <dt>
        <label for="mobile">Mobile:</label>
      </dt>
      <dd>
        <input type="text" name="mobile" id="mobile" tabindex="12"/>
      </dd>
      <dt>
        <label for="fax">Work:</label>
      </dt>
      <dd>
        <input type="text" name="work" id="work" value='' tabindex="13"/>
      </dd>
      <dt>
        <label for="fax">Work2:</label>
      </dt>
      <dd>
        <input type="text" name="work2" id="work2" value='' tabindex="13"/>
      </dd>
      <dt>
        <label for="fax">Fax:</label>
      </dt>
      <dd>
        <input type="text" name="fax" id="fax" tabindex="14"/>
      </dd>
      <dt>
        <label for="email">E-Mail:</label>
      </dt>
      <dd>
        <input type="text" name="email" id="email" tabindex="15"/>
      </dd>
      <dt>
        <label for="email2">E-Mail2:</label>
      </dt>
      <dd>
        <input type="text" name="email2" id="email2" tabindex="16"/>
      </dd>
      <dt>
        <label for="email2">E-Mail3:</label>
      </dt>
      <dd>
        <input type="text" name="email3" id="email3" tabindex="17"/>
      </dd>
    </div>
    <div class="barRight">
      <dt>
        <label for="yahoo">Yahoo:</label>
      </dt>
      <dd>
        <input type="text" name="yahoo" id="yahoo" tabindex="18"/>
      </dd>
      <dt>
        <label for="msn">MSN:</label>
      </dt>
      <dd>
        <input type="text" name="msn" id="msn" tabindex="19"/>
      </dd>
      <dt>
        <label for="icq">ICQ:</label>
      </dt>
      <dd>
        <input type="text" name="icq" id="icq" tabindex="20"/>
      </dd>
      <dt>
        <label for="jabber">Jabber:</label>
      </dt>
      <dd>
        <input type="text" name="jabber" id="jabber" tabindex="21"/>
      </dd>
      <dt>
        <label for="gtalk">Google Talk:</label>
      </dt>
      <dd>
        <input type="text" name="gtalk" id="gtalk" tabindex="22"/>
      </dd>
      <dt>
        <label for="aim">AIM:</label>
      </dt>
      <dd>
        <input type="text" name="aim" id="aim" tabindex="23"/>
      </dd>
      <dt>
        <label for="skype">Skype:</label>
      </dt>
      <dd>
        <input type="text" name="skype" id="skype" tabindex="24"/>
      </dd>
    </div>
  </dl>
  <div class="barsubmit">
    <dl>
      <input type="submit" name="save" id="fsave" value="Save" class="button" tabindex="25" />
    </dl>
  </div>
  </fieldset>
</form>
Return current item: Php AddressBook 2