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?
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.
Comments