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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:34:08+00:00 2026-06-13T11:34:08+00:00

I am trying to create table to my database from php. I kinda trying

  • 0

I am trying to create table to my database from php. I kinda trying to make a social networking site, anyway, I wrote the code and is working but new table won’t create in database, I don’t know what seems to be wrong with the code. Help will be much appreciated thanks!

<?php

    $host = "host";   
    $user = "user";
    $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 ("Database Not Selected");
    }

        $sql = "CREATE TABLE IF NOT EXIST 'friends' 
            (
            'friend_id' INT NOT NULL auto_increment, 
            'friend_email' VAR CHAR(20) NOT NULL,
            'password' VAR CHAR(20) NOT NULL,
            'profile_name' VAR CHAR(30) NOT NULL,
            'date_started' DATE NOT NULL,
            'num_of_friends' INT unsigned,
            PRIMARY KEY ('friend_id')
            )";

    $query_result = @mysqli_query($conn, $sql);


    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-13T11:34:09+00:00Added an answer on June 13, 2026 at 11:34 am

    You need to check for errors when running scripts also, so either turn off suppression (remove the @ symbol) or else check for an error after running.

    There were in fact multiple errors:

    1. You had EXIST rather than EXISTS
    2. You used single quotes ( ‘ ) rather than the ` mark
    3. You had VAR CHAR as two words, rather than the correct VARCHAR (one word)

        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`)  
            )
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an html table from database records. I want the table
Possible Duplicate: outputting values from database into html table PHP I am trying to
I'm trying to create a basic database trigger that conditionally deletes rows from database1.table1
I am trying to create this table in a MySQL database CREATE TABLE IF
I am trying to create an application which requires a two table SQLite database
I'm trying to create a database with 12 different tables which has been working
I'm trying to create table from view from remote server (calling procedure UPDATE_PROC), like
I'm trying to create a table in php that would show the data on
I'm trying to create a table of information in a database query using Zend
I'm trying to create a report from a proprietary ERP database. I've set up

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.