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

  • SEARCH
  • Home
  • 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 6687569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:18:16+00:00 2026-05-26T05:18:16+00:00

I have two functions addCategory, and addArticle as follows : function addCategory(){ $title=$_POST[‘title’]; $description=$_POST[‘description’];

  • 0

I have two functions addCategory, and addArticle as follows :

function addCategory(){

$title=$_POST['title'];
$description=$_POST['description'];
$photo=$_FILE['photo'];

$cmd='INSERT INTO tbl_categ(title,description,photo)VALUES(:title,:description,:photo)';

$stmt=$pdo->prepare($cmd);
$stmt->bindParam(':title',$title);
$stmt->bindParam(':description',$description);
$stmt->bindParam(':photo',$photo);

$stmt->execute();
}

and this is the function addArticle:

function addArticle(){

$title=$_POST['title'];
$id_categ=$_POST['id_categ'];
$texte=$_POST['texte'];
 $keywords=$_POST['keywords'];
$photo=$_FILE['photo'];

$cmd='INSERT INTO tbl_categ(id_categ,title,texte,keywords,photo)VALUES(:id_categ,:title,:texte,:keywords,:photo)';

$stmt=$pdo->prepare($cmd);
$stmt->bindParam(':id_categ',$id_categ);
$stmt->bindParam(':title',$title);
$stmt->bindParam(':texte',$texte);
$stmt->bindParam(':keywords',$keywords);
$stmt->bindParam(':photo',$photo);

$stmt->execute();
}

As you can see, those two functions are doing the same task but with different tables… it’s about an “Add” action… so my goal is to make just one add function which will be working for every “adding” action whatever is it’s number of POST parameters (coming from forms) , whatever is the number of fields in the table, and whatever is the table in the database.

I’ve got an idea about adding a parameter to this function, which will define the name of the table where the data will be stored , and every form has his own table name, But how can the function determine the number of table’s fields , and the names of those fields to use them in the command string?

Thank you in advance

  • 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-26T05:18:17+00:00Added an answer on May 26, 2026 at 5:18 am

    You can determine the table’s fields by using DESCRIBE TABLE. After that, you might find it cleaner to store this in a class, instead of having a lot of global variables floating around.

    After that, you might want to optimize by caching the DESCRIBE TABLE results, so you don’t have to grab them each time.

    After that, you might realize that you have essentially recreated what most Active Record type libraries try to do, and you’re better off just using one of those.

    Doctrine is a good choice (although it uses code generation instead).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions, one that creates a table like so: function return_formatted_results(result_no,addy,title,own_comment) {
I have two functions in an ActionScript class, they are: private function loaderCompleteHandler(event:Event):void {
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
I have two Python functions, both of which take variable arguments in their function
I have two functions function ShowCrossWord(var randN) { randomnumber = randN; $(document).ready(function() { $.get(crosswords.xml,{},function(xml){
I have two functions, one which parses all the arguments sent to the function
I have two functions whose execution time I would like to compare: function subject_one()
I have two functions written in VB.NET: 1) The first function (call it GetValues())
I have two functions. The first function translates a div click into a checked/unchecked
I have two functions, one function calling the other. Below is a simple analogy

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.