How to create a table in database using jquery

seal

I have a button that when pressed will create a table in the database. I tried this

index.html

<button id="loadButton" type="button" class="btn btn-success" style="margin-top:5px;">Carregar Base de Dados</button>

dash.js

$('#loadButton').click(function() {
    $.ajax({
        url: 'connectdb.php'
    });
});

connectdb.php

<?php

$server = 'localhost';
$user = 'root';
$password = '*****';
$database = 'test';

$con = mysql_connect($server, $user, $password, $database);

if (!$con) {
  die('error: ' . mysql_error($con));
}

// Create table
$sql="CREATE TABLE Post( 
    id_post int Primary Key, 
    titulo varchar(100) not null, 
    imagem longblob,
    descricao varchar(1000) not null,
    hashtag varchar(100) not null
)";

// Execute query
mysql_query($con,$sql))
?>

?>

but when I check my database table was not created. I'm new in jquery, what I'm doing wrong. can someone help me?

Max Hutschenreiter

Try this and if you want to be shure the php code is called replace all the code with an simple echo and check the response.

$server = 'localhost';
$user = 'root';
$password = '*****';
$database = 'test';

$db = new mysqli($server, $user, $password, $database);

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

$db->query("
CREATE TABLE Post( 
    id_post int Primary Key, 
    titulo varchar(100) not null, 
    imagem longblob,
    descricao varchar(1000) not null,
    hashtag varchar(100) not null
)");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I create a new table in my SQLite Database using a param from a Java String variable?

How to create a list view from a database table?

Create table error in MYSQL database using Python

How to create a backup of a single table in a postgres database?

How to create database schema (table) in Laravel?

Create variable in database using ALTER TABLE and UPDATE

How to Create dynamic table with json object using jquery

How to create another table in database with SugarORM

How to create a table and choose any column in database?

How to create table under a schema in a database

How to create a new table into a database on android studio?

unable to create table using jquery

How create auto suggestion textbox in c# using DataBase table

How to create a table using a loop?

How to create table in Sqlite Database in android

how to create a table if it does not exist it database using php?

How to create a table in database using wordpress plugin

How to create a table using PDFsharp?

How to create a copy of an SQLite database table on Android?

How to create a new table in database using sapui5?

How to create an Intermediary table for a M:M database

How do i create a table using Jquery

Unable to create table in Database using Hibernate

How to create table using oracle database

How to create a table using xslt

Create table using jQuery and .append

Anylogic: How to create plot from database table?

How can I create a table using a query on a graph database such that the node properties become the fields in the table?

How to create a table from remote database using dblink