Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 307987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:36:32+00:00 2026-05-12T07:36:32+00:00

I am facing some problems converting the PHP SQL insertion code below to ASP,

  • 0

I am facing some problems converting the PHP SQL insertion code below to ASP, I want to use the same concept in ASP, because it is more flexible, not tied to ASP owned keywords.

Wonder if anyone can help ASP newbie here.

$table = 'tbluser';
$array = array (
        'name' => $name,
        'email' => $email,
        'ip' => $remoteIP
        );
$newid = insert_query ($table, $array); 



  function insert_query ($table, $array)
  {
    global $mysql_errors;
    $query = 'INSERT INTO ' . $table . ' ';
    foreach ($array as $key => $value)
    {

      $fieldnamelist .= '' . '`' . $key . '`,';
      if ($value == 'now()')
      {
        $fieldvaluelist .= 'now(),';
        continue;
      }
      else
      {
        $fieldvaluelist .= '\'' . $value . '\',';
        continue;
      }
    }

    $fieldnamelist = substr ($fieldnamelist, 0, 0 - 1);
    $fieldvaluelist = substr ($fieldvaluelist, 0, 0 - 1);
    $query .= '' . '(' . $fieldnamelist . ') VALUES (' . $fieldvaluelist . ')';
    $result = mysql_query ($query);
    if (!$result)
    {
      $message = 'Invalid query: ' . mysql_error () . '<br>';
      $message .= 'Whole query: ' . $query;
    }

    $id = mysql_insert_id ();
    return $id;
  }

it’s classic ASP. No choice, company still need to maintain this for a specific project.

The main reason I want this specific code style in ASP is because I don’t want to tie to the ASP style of querying database (using cmd and etc…)

By creating array collection with key(table fieldname) and value, then convert into a full sql string, I only need to run .execute(sql) , it means in future I can more easier convert the project to other framework, without needing to rewrite the way to insert/update data into DB.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:36:32+00:00Added an answer on May 12, 2026 at 7:36 am

    Not exactly the same, but here are some functions I’ve used in ASP classic sites.
    I think it should be a good starting point for learning.

    Function AddUser(Name, Email, IP )
        dim sqlstmt
        sqlstmt = "INSERT INTO tbluser (Name, Email, IP )"
        sqlstmt = sqlstmt & " values (?, ?, ?)"
        call RunSQL( sqlstmt, array( _
            mp("@Name", adVarChar, 100, Name), _
            mp("@Email", adVarChar, 100, Email), _
            mp("@IP", adVarChar, 100, IP)))
    end Function
    
    Function RunSQL(strSqlStmt , params())
        On Error resume next
    
        ''// Create the ADO objects
        Dim cmd
        Set cmd = server.createobject("ADODB.Command")
    
        ''// Init the ADO objects & the stored proc parameters
        cmd.ActiveConnection = GetConnectionString()
        cmd.CommandText = strSqlStmt
        cmd.CommandType = adCmdText
        collectParams cmd, params
    
        ''// Execute the query without returning a recordset
        cmd.Execute , , adExecuteNoRecords
        If err.number > 0 then
            BuildErrorMessage()
            exit function
        end if
    
        ''// Cleanup
        Set cmd.ActiveConnection = Nothing
        Set cmd = Nothing
    
        Exit Function
    
    End Function
    
    
    Private Sub collectParams(cmd , argparams())
        Dim params , v
        Dim i , l , u
    
        params = argparams
    
    
        For i = LBound(params) To UBound(params)
            l = LBound(params(i))
            u = UBound(params(i))
    
            ''// Check for nulls.
            If u - l = 3 Then
                If VarType(params(i)(3)) = vbString Then
                    If params(i)(3) = "" then
                                        v = null
                    else
                        v = params(i)(3)
                    end if
                Else
                    v = params(i)(3)
                End If
    
            If params(i)(1) = adLongVarChar Then
                    Dim p ''// As New Parameter
                    Set p = cmd.CreateParameter(params(i)(0), params(i)(1), adParamInput)
                    p.Attributes = adParamLong + adParamSigned
                    If Not IsNull(v) Then
                        p.AppendChunk v
                        p.Size = Len(v)
                    Else
                        p.Value = v
                        p.Size = 10000
                    End If
                    cmd.Parameters.Append p
                Else
                    cmd.Parameters.Append cmd.CreateParameter(params(i)(0), params(i)(1), adParamInput, params(i)(2), v)
                End If
            Else
                RaiseError m_modName, "collectParams(...): incorrect # of parameters"
            End If
        Next
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 178k
  • Answers 178k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If ASP.NET Request Validation is enabled for a site, do… May 12, 2026 at 3:43 pm
  • Editorial Team
    Editorial Team added an answer Web Services are meant to be platform independent - unless… May 12, 2026 at 3:43 pm
  • Editorial Team
    Editorial Team added an answer I do this on my mapping project site. I have… May 12, 2026 at 3:43 pm

Related Questions

This is almost similar question to this one: - Dealing with timezones in PHP
My application is preparing a cover-sheet for submitting documents by fax. I identify the
i am currently working with MEF and facing some problems what i want is
Im facing some problems, I looked around in the forum and didnt find any

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.