Thank you superdezign for taking the time to write so much; I'm grateful. I going through your posting piece by piece and testing. I'm on the str_replace for the moment, which I think is wonderfully simple and makes perfect sense even for a beginner. Surprisingly though, it's not working! I copy/pasted directly with no changes. I looked it up and you appear to have it right from what I've read, so not sure why it wouldn't be working. I even moved the block of code to all different parts of the page just to make sure... nothing.
The STR_REPLACE seems the most simple and intuitive, so if we can get that to work that would be great.
I'm going to place my code below. Maybe I'm not revealing something that will make all the difference:
Code: Select all
<?php
// Connect to server then db and return error if not completed
include_once ("../_includes/dbconnect.php");
$b_firstname = "";
$b_lastname = "";
$b_address = "";
$b_address2 = "";
$b_city = "";
$b_state = "";
$b_zipcode = "";
$b_ssn = "";
$b_birthday = "";
$b_dl = "";
$b_phone_h = "";
$b_phone_m = "";
$b_phone_w = "";
$cb_firstname = "";
$cb_lastname = "";
$cb_address = "";
$cb_address2 = "";
$cb_city = "";
$cb_state = "";
$cb_zipcode = "";
$cb_ssn = "";
$cb_birthday = "";
$cb_dl = "";
$cb_phone_h = "";
$cb_phone_m = "";
$cb_phone_w = "";
if (isset($_POST['submit']))
{
$b_firstname = $_POST['b_firstname'];
$b_lastname = $_POST['b_lastname'];
$b_address = $_POST['b_address'];
$b_address2 = $_POST['b_address2'];
$b_city = $_POST['b_city'];
$b_state = $_POST['b_state'];
$b_zipcode = $_POST['b_zipcode'];
$b_ssn = $_POST['b_ssn'];
$b_birthday = $_POST['b_birthday'];
$b_dl = $_POST['b_dl'];
$b_phone_h = $_POST['b_phone_h'];
$b_phone_m = $_POST['b_phone_m'];
$b_phone_w = $_POST['b_phone_w'];
$cb_firstname = $_POST['cb_firstname'];
$cb_lastname = $_POST['cb_lastname'];
$cb_address = $_POST['cb_address'];
$cb_address2 = $_POST['cb_address2'];
$cb_city = $_POST['cb_city'];
$cb_state = $_POST['cb_state'];
$cb_zipcode = $_POST['cb_zipcode'];
$cb_ssn = $_POST['cb_ssn'];
$cb_birthday = $_POST['cb_birthday'];
$cb_dl = $_POST['cb_dl'];
$cb_phone_h = $_POST['cb_phone_h'];
$cb_phone_m = $_POST['cb_phone_m'];
$cb_phone_w = $_POST['cb_phone_w'];
/*
// Sanitize all phone number entries to our preferred format
$b_phone_h = preg_replace('/[\()]/', '', $b_phone_h); // Remove ( & )
$b_phone_h = preg_replace('/[ .]/', '-', $b_phone_h); // Remove any 'spaces' & '.' and replace with -
$b_phone_m = preg_replace('/[\()]/', '', $b_phone_m); // Remove ( & )
$b_phone_m = preg_replace('/[ .]/', '-', $b_phone_m); // Remove any 'spaces' & '.' and replace with -
$b_phone_w = preg_replace('/[\()]/', '', $b_phone_w); // Remove ( & )
$b_phone_w = preg_replace('/[ .]/', '-', $b_phone_w); // Remove any 'spaces' & '.' and replace with -
$cb_phone_h = preg_replace('/[\()]/', '', $cb_phone_h); // Remove ( & )
$cb_phone_h = preg_replace('/[ .]/', '-', $cb_phone_h); // Remove any 'spaces' & '.' and replace with -
$cb_phone_m = preg_replace('/[\()]/', '', $cb_phone_m); // Remove ( & )
$cb_phone_m = preg_replace('/[ .]/', '-', $cb_phone_m); // Remove any 'spaces' & '.' and replace with -
$cb_phone_w = preg_replace('/[\()]/', '', $cb_phone_w); // Remove ( & )
$cb_phone_w = preg_replace('/[ .]/', '-', $cb_phone_w); // Remove any 'spaces' & '.' and replace with -
*/
/* Previous attempt with preg_replace. Not working
$phoneType = array('$b_phone_h', '$b_phone_m', '$b_phone_w', '$cb_phone_h', '$cb_phone_m', '$cb_phone_w');
foreach ($phoneType as $value) {
$value = preg_replace('/[\()]/', '', $value) ;
$value = preg_replace('/[ .]/', '-', $value) ;
}
*/
$replaceThese = array('(', ')', ' ', '.');
$withThese = array( '', '', '-', '-');
str_replace($replaceThese, $withThese, $b_phone_h);
// Insert data from form into db fields
$sql = "INSERT contact_info (
b_firstname,
b_lastname,
b_address,
b_address2,
b_city,
b_state,
b_zipcode,
b_ssn,
b_birthday,
b_dl,
b_phone_h,
b_phone_m,
b_phone_w,
cb_firstname,
cb_lastname,
cb_address,
cb_address2,
cb_city,
cb_state,
cb_zipcode,
cb_ssn,
cb_birthday,
cb_dl,
cb_phone_h,
cb_phone_m,
cb_phone_w)
VALUES (
'$b_firstname',
'$b_lastname',
'$b_address',
'$b_address2',
'$b_city',
'$b_state',
'$b_zipcode',
'$b_ssn',
'$b_birthday',
'$b_dl',
'$b_phone_h',
'$b_phone_m',
'$b_phone_w',
'$cb_firstname',
'$cb_lastname',
'$cb_address',
'$cb_address2',
'$cb_city',
'$cb_state',
'$cb_zipcode',
'$cb_ssn',
'$cb_birthday',
'$cb_dl',
'$cb_phone_h',
'$cb_phone_m',
'$cb_phone_w')";
// Check connection and insert data. If problem, indicate an error
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
// ---------------------------------------------------------------
$id = mysql_insert_id();
$q = "Select * from contact_info where id=".$id;
$re = mysql_query($q);
if (!$re)
die(mysql_error());
else
{
$ro = mysql_fetch_object($re);
$b_firstname = $ro->b_firstname;
$b_lastname = $ro->b_lastname;
$b_address = $ro->b_address;
$b_address2 = $ro->b_address2;
$b_city = $ro->b_city;
$b_state = $ro->b_state;
$b_zipcode = $ro->b_zipcode;
$b_ssn = $ro->b_ssn;
$b_birthday = $ro->b_birthday;
$b_dl = $ro->b_dl;
$b_phone_h = $ro->b_phone_h;
$b_phone_m = $ro->b_phone_m;
$b_phone_w = $ro->b_phone_w;
$cb_firstname = $ro->cb_firstname;
$cb_lastname = $ro->cb_lastname;
$cb_address = $ro->cb_address;
$cb_address2 = $ro->cb_address2;
$cb_city = $ro->cb_city;
$cb_state = $ro->cb_state;
$cb_zipcode = $ro->cb_zipcode;
$cb_ssn = $ro->cb_ssn;
$cb_birthday = $ro->cb_birthday;
$cb_dl = $ro->cb_dl;
$cb_phone_h = $ro->cb_phone_h;
$cb_phone_m = $ro->cb_phone_m;
$cb_phone_w = $ro->cb_phone_w;
}
mysql_close($con) ;
}
?>
Thanks again for any help...