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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:23:18+00:00 2026-06-13T15:23:18+00:00

I have this task from school, and I am confuse and lost on how

  • 0

I have this task from school, and I am confuse and lost on how I got to do this.
So basically I have to create 2 tables to the database but I have to created from php.

I have created the first table, but not the second one for some reason.
And then, I have to populate first and second tables with 10 and 20 sample records respectively, populate, does it mean like adding more fake users? if so is it like the code shown below?

*I got error on the populating second part as well

Thank you so much for the help.

<?php
        $host = "host";
        $user = "me";
        $pswd = "password";
        $dbnm = "db";

        $conn = @mysqli_connect($host, $user, $pswd, $dbnm);
        if (!$conn)
            die ("<p>Couldn't connect to the server!<p>");

        $selectData = @mysqli_select_db ($conn, $dbnm);
        if(!$selectData)
        {
            die ("<p>Database Not Selected</p>");
        }

        //1st table
            $sql =  "CREATE TABLE IF NOT EXISTS  `friends`  
          (  
          `friend_id` INT NOT NULL auto_increment,   
          `friend_email` VARCHAR(20) NOT NULL,  
          `password` VARCHAR(20) NOT NULL,  
          `profile_name` VARCHAR(30) NOT NULL,  
          `date_started` DATE NOT NULL,  
          `num_of_friends` INT unsigned,  
          PRIMARY KEY (`friend_id`)  
          )";

        //2nd table
          $sqlMyfriends = "CREATE TABLE `myfriends`
          (  
          `friend_id1` INT NOT NULL,   
          `friend_id2` INT NOT NULL,
          )";


        $query_result1 = @mysqli_query($conn, $sql);
        $query_result2 = @mysqli_query($conn, $sqlMyfriends);

        //populating 1st table
        $sqlSt3="INSERT INTO friends (friend_id, friend_email, password, profile_name, date_started, num_of_friends) 
                VALUES('NULL','email@email.com','123','abc','2012-10-25', 5)";
        $queryResult3 = @mysqli_query($dbConnect,$sqlSt3)


        //populating 2nd table
        $sqlSt13="INSERT INTO myfriends VALUES(1,2)";
        $queryResult13=@mysqli_query($dbConnect,$sqlSt13);


        mysqli_close($conn);

    ?>
  • 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-13T15:23:19+00:00Added an answer on June 13, 2026 at 3:23 pm

    The others have addressed one of your issues, so this is in relation to not being able to add values to your tables (populate). Your connection link is $conn –

    $conn = @mysqli_connect($host, $user, $pswd, $dbnm);
    ie.
       $query_result1 = @mysqli_query($conn, $sql);
    

    but when you are adding your values to the tables, you changed your connection link to $dbConnect

    ...
    $queryResult3 = @mysqli_query($dbConnect,$sqlSt3)
    ...
    $queryResult13=@mysqli_query($dbConnect,$sqlSt13);
    

    To insert multiple values into your table you could add a comma and additional parentheses ,() –

        //populating 2nd table
        $sqlSt13="INSERT INTO myfriends VALUES(1,2),(2,3),(3,1)";
        $queryResult13=@mysqli_query($conn,$sqlSt13); 
    

    Or you could use mysqli_multi_query, and list each one-

        //populating 2nd table
        $sqlSt13  ="INSERT INTO myfriends VALUES (1,2);";
        $sqlSt13 .="INSERT INTO myfriends VALUES (2,3);";
        $sqlSt13 .="INSERT INTO myfriends VALUES (3,1);";
        $queryResult13=@mysqli_query($conn,$sqlSt13);
    

    see the manual for mysqli_multi_query – php.net/manual/en/mysqli.multi-query.php

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

Sidebar

Related Questions

Sorry for this long post....But i have a headache from this task. I have
I have this Maven task to generate Java classes from an XSD file using
Ok, I am back on this task. I have my XML properly download from
I have some basic idea on how to do this task, but I'm not
I have a task of copying the data from one database to another.I don't
Was'nt sure of the title, but I have this task which I am having
I am trying to do this task from the past 12 hour, but still
I have this task for the project with 4 nested subprojects using Maven: For
I have this little rake task: namespace :db do namespace :test do task :reset
Assume I have this model : class Task(models.Model): title = models.CharField() Now I would

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.