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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.