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 8907751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:59:48+00:00 2026-06-15T02:59:48+00:00

why my code is not working here I think I made something wrong but

  • 0

why my code is not working here I think I made something wrong but I just can not determine it if anyone can spot what I have made wrong here I will be thankfull

here is my code: I am trying here to use php class to insert new row in the database

<?php
$connection = new PDO('mysql:dbname=master;host=localhost','root','123');
/*if($connection)
{
    echo 'Database is connected successfully';
}
else
     {
    echo 'please connect to a database';
}*/
class Topics
{
    public $id;
    public $title;
    public $body;
    public static $table_name = 'topics';
    public static $fields = array ('title','body');
    private function attributes()
    {
        $string = array();  
        foreach (self::$fields as $field) 
        {
            if (!empty($field)) {
                if(is_int($this->$field))
                {
                    $string[] = $field." =".$this->$field;
                }
                else
                {
                    $string[] = $field." ="."'".$this->$field."'";
                }

            }   

        }
        return join(',', $string);
    }
    public function add()
    {
        global $connection;
        $sql = 'INSERT INTO'.self::$table_name.'SET'.$this->attributes();
        $number_of_affected_rows = $connection->exec($sql);
        if($number_of_affected_rows >0)
        {
            $this->id = $connection->lastInsertId();
        }
        return ($number_of_affected_rows>0) ? $number_of_affected_rows : FALSE;
    }
}
$mohamed = new Topics();
$mohamed->title = 'Hello';
$mohamed->body = 'Hello world again';
return $mohamed->add();
?>
  • 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-06-15T02:59:50+00:00Added an answer on June 15, 2026 at 2:59 am

    What’s not working exactly? Your SQL is wrong anyway, beacause it needs whitespaces in it.

    'INSERT INTO '.self::$table_name.' SET '.$this->attributes();

    And btw you should also escape table and field name in your SQL.

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

Sidebar

Related Questions

i have implemented code like here but it's not working for iOS 5.0, it
Got this line of code here but its not working. private void Button_Click(object sender,
Here's the code for a simple page I have that is not working: <head>
Here's my code that is not working: print To: ; my $to=<>; chomp $to;
ProgressDialog onClick not working.. here is my code .. Basically i want to show
Here is what I am currently using for the code and it's not working
can anybody tell me why is the following code not working? <script type=text/javascript src=../../Scripts/jquery.js></script>
current code (not working): /^script\s*type=\text\/javascript/i.test(tagName)
Why is the following code not working? if(EventLog.Exists(Foo)) { EventLog.Delete(Foo); } if(EventLog.Exists(Foo) == false)
i am using python 2.5.2 . The following code not working. def findValue(self, text,

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.