Jump to content

Possible explode() and/or function problem.


acctman

Recommended Posts

I'm not getting any errors but its also not INSERTing into the database. Without an error I can figure out whats wrong.

 


$db_server = 'localhost';
$db_user = 'user_db';
$db_pass = 'password';

$dbc = mysql_connect ($db_server, $db_user, $db_pass);
if (!$dbc) { 
    die(mysql_error());
    header ('Location: /form');
    exit;
}

if (is_array($_POST)) {
        foreach ($_POST as $key => $value) {
            $_POST[$key] = mysql_real_escape_string(stripslashes($value));
        }
    }

    $xRequestType      = $_POST["xRequestType"];
    $xConsumerBusiness = $_POST["xConsumerBusiness"];
    $xGlobalLocation   = $_POST["xGlobalLocation"];
    $xFirstName        = strtolower(str_replace("'","''",$_POST["xFirstName"]));
    $xFirstName        = strtoupper(substr($xFirstName,0,1)).substr($xFirstName,1);
    $xLastName         = strtolower(str_replace("'","''",$_POST["xLastName"]));
    $xLastName         = strtoupper(substr($xLastName,0,1)).substr($xLastName,1);
    $xEmail            = strtolower(str_replace("'","''",$_POST["xEmail"]));
    $xTitle            = strtolower(str_replace("'","''",$_POST["xTitle"]));

function dbSet($fields, $source = array()) {
    $set='';
    if (!source) $source = &$_POST;
    foreach ($fields as $field) {
        if (isset($source[$field])) {
            $set.="`$field`='".mysql_real_escape_string($source[$field])."', ";
        }
    }
    return substr($set, 0, -2);
}

// INSERT INTO DATABASE
            mysql_select_db("new_contact",$dbc) or die("Could not select new_contact");
            
$fields =   explode(" ", "xRequestType xConsumerBusiness xGlobalLocation xFirstName xLastName xEmail xTitle xCompany xAddress xCity xState xZip xPhone xFax xProductDesc xComment");
            $query = "INSERT INTO new_contact SET ".dbSet($fields, $_POST);
            mysql_query($query);

Link to comment
https://forums.phpfreaks.com/topic/262067-possible-explode-andor-function-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.