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?
mysql_query->mysql_query($sql,$link),mysqli_query->mysqli_query($link,$sql). Update tomysqli. Also, you may want to useCREATE TABLE IF NOT EXISTS Posts, as if you click again it will overwrite your table.